GithubHelp home page GithubHelp logo

laravel-startercrud's Introduction

Laravel Starterkit Artisan CRUD

Latest Stable Version Total Downloads License

This is an Artisan based package for the Laravel Starterkit

Install

Via Composer

$ composer require leogopal/laravel-startercrud

Usage

Creates a Model, Controller (with Repository, validation Requests, Events and Listeners), Migration, Routes, Breadcrumbs and CRUD Views for the given name ready to work.

It does not overwrite any files that may exist with the pre-stablished names. So, if you delete one of the files and run the command again, the deleted file will be created again and the rest will be ignored and will keep the changes you could have made.

Run

In your Laravel project root folder:

php artisan lg:crud example

Where example is the name you want for your model (routes, views, controllers,...). I've tried to follow best naming practices and it uses plural or singular names and lower or uppercase where needed. You can also use camelCase or snake_case.

Parameters example, Example, examples or EXAMPLES all give the same results.

Then run the created migration:

php artisan migrate

In your browser open:

https://YOUR_SITE/admin/examples

...et voilà! :)

Note: out of the box, the table comes only with a title text field, besides the id, deleted_at, created_at and updated_at. Edit your newly created migration file to add any other you may need before runnning the migrate command.

Options

You can create all the files and run the migration by running the command with the --migrate option:

php artisan lg:crud example --migrate

or

php artisan lg:crud example -m

You may also specify the name of the default text field 'title' to whatever other you prefer with the --field option:

php artisan lg:crud example --field=name

or

php artisan lg:crud example -f name

Include a menu item

A file named sidebar-examples.blade.php is created in the folder /resources/views/backend/example/includes. It contains the html code for a menu item to access your recently created views. You can show it in your sidebar by including the following line in /resources/views/backend/includes/sidebar.blade.php wherever you want it to appear:

@include('backend.example.includes.sidebar-examples')

Events and Listeners

The package generates three events and listeners for creating, updating and deleting items methods. In order to get these to work you must resgister them with the event dispatcher, adding this line to your Providers/EventServiceProvider.php file (under Backend Subscribers):

\App\Listeners\Backend\Example\ExampleEventListener::class

Language lines

Following are the labels.php, menus.php and validation.php English language lines needed, copy them into the files in /resources/lang/en or whatever other language folder you may need. Replace Example for the name of your Model.

TODO: generate a file with all the customized language lines ready to copy&paste.

labels.php under 'backend':

'examples' => [
    'management'    => 'Example Management',
    'active'        => 'Active Examples',
    'view'          => 'View Example',
    'edit'          => 'Edit Example',
    'create'        => 'Create Example',
    'create_new'    => 'Create New Example',
    'table'         => [
        'title'         => 'Title',
        'created'       => 'Created',
        'last_updated'  => 'Last Updated',
        'deleted'       => 'Deleted',
        'actions'       => 'Actions',
        'tab_title'     => 'Overview',
        'total'         => 'example total|examples total',
    ],

    'tabs' => [
        'title' => 'Overview',
        'content' => [
            'overview'  => [
                'title'         => 'Title',
                'created_at'    => 'Created',
                'last_updated'  => 'Last Updated',
            ],
        ],
    ],

],

_Warning: If you have used the --field option, you should change tabs->content->overview->title to match the field name you have chosen._

menus.php under 'backend'

'examples' => [
    'main'            => 'Examples',
    'all'             => 'All Examples',
    'create'          => 'Create Example',
    'deleted'         => 'Deleted Examples',
    'view'            => 'View Example',
    'edit'            => 'Edit Example',
],

menus.php under 'backend' => 'sidebar'

'examples'  => 'Examples',

validation.php under 'attributes' => 'backend'

'examples' => [
    'title'            => 'Title',
],

_Warning: If you have used the --field option, you should change 'title' to match the field name you have chosen.

alerts.php under 'backend'

'examples' => [
    'created'                   => 'The example was successfully created.',
    'updated'                   => 'The example was successfully updated.',
    'deleted'                   => 'The example was successfully deleted.',
    'restored'                  => 'The example was successfully restored.',
    'deleted_permanently'       => 'The example was deleted permanently.',
],

buttons.php under 'backend'

'examples' => [
    'restore' => 'Restore Example',
    'delete_permanently'    => 'Permanently delete Example',
],

exceptions.php under 'backend'

'examples' => [
    'cant_restore'          => 'This Example is not deleted so it can not be restored.',
    'delete_first'          => 'This Example must be deleted first before it can be destroyed permanently.',
]

Files created

Model

app/Models/Example.php

Trait Attribute

app/Models/Traits/Attribute/ExampleAttribute.php

This is where the action buttons for the new object are.

Controller

app/Http/Controllers/Backend/ExampleController.php

It contains the CRUD methods: index, create, store, show, edit, update, destroy, delete, restore and deleted.

Repository

app/Repositories/Backend/ExampleRepository.php

Contains database logic.

Requests

app/Http/Requests/Backend/ManageExampleRequest.php
app/Http/Requests/Backend/StoreExampleRequest.php
app/Http/Requests/Backend/UpdateExampleRequest.php

Validation manage, store and update Requests.

Events

app/Events/Backend/Example/ExampleCreated.php
app/Events/Backend/Example/ExampleUpdated.php
app/Events/Backend/Example/ExampleDeleted.php

Listeners

app/Listeners/Backend/Example/ExampleEventListener.php

Migrations

database/migrations/\YYYY_MM_DD_create_examples_table.php

Routes

routes/backend/examples.php

Contains the named routes admin.examples.index, admin.examples.deleted, admin.examples.restore, delete-permanently, admin.examples.create, admin.examples.store, admin.examples.show, admin.examples.edit, admin.examples.update and admin.examples.destroy.

Breadcrumbs

routes/breadcrumbs/backend/example.php

This has the breadcrumbs for the routes admin.examples.index, admin.examples.create, admin.examples.show, admin.examples.edit and admin.examples.deleted.

The following line is added to routes/breadcrumbs/backend/backend.php:

require **DIR**.'/example.php';

If you delete the routes/breadcrumbs/backend/example.php file created by this command, don't forget to delete this line or your whole project will crash.

Views

resources/views/backend/example/index.blade.php
resources/views/backend/example/show.blade.php
resources/views/backend/example/create.blade.php
resources/views/backend/example/edit.blade.php
resources/views/backend/example/deleted.blade.php
resources/views/backend/example/includes/breadcrumb-links.blade.php
resources/views/backend/example/includes/header-buttons.blade.php

If you add more fields to your datatable, you'll have to edit show.blade.php, create.blade.php and edit.blade.php to suit your needs.

Menu item

sidebar-examples.blade.php

HTML code for the menu item for your Laravel 5 starterkit sidebar.

License

The MIT License (MIT). Please see License File for more information.

laravel-startercrud's People

Contributors

leogopal avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.