thijsdemaa / laravel-crud
This package's canonical repository appears to be gone and the package has been frozen as a result.
Requires
- php: >=5.5
- mustache/mustache: ~2.5
Requires (Dev)
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2020-03-06 16:52:56 UTC
README
This is a simple package for generating CRUD Models, Controllers and Views for a resource.
Installation
- Pull in through composer
composer require thijsdemaa/laravel-crud
- Add the service provider to
config/app.php
LaravelCrud\CrudServiceProvider::class
Quick Start
In this example we will quickly create
a model, migration, controller and viewsfor a Person resource,
where we want the route to be admin/person
,
and the view-files to be put in the folder admin/resources
.
Check the fields section to see which fields are available.
php artisan crud:model Person --fields="first_name:string, last_name:string, email:string, password:string, address:string, age:integer, active:boolean"
php artisan migrate
php artisan crud:controller Person --fields="first_name:string, last_name:string, email:email, password:string, address:string, age:integer, active:boolean" --view-path="admin.resources" --route-prefix="admin"
php artisan crud:view Person --fields="first_name:string, last_name:string, email:email, password:password, address:string, age:integer, active:boolean" --view-path="admin.resources" --route-prefix="admin"
If you have added the route to the routes.php
like specified after running the controller-command,
you are now ready to use your new crud-application by navigating to /admin/person.
Features
Creating:
- Models
- Migrations
- Controllers
- Views
Uses functions of Laravel like:
route()
helper for all the routing.str_plural()
helper for migrations and views, so that person becomes people.- Pagination on the index page.
Documentation
Creating a Model
Command: php artisan crud:model
Description: This command will create a model and a migration file for the resource.
Option | Description |
---|---|
Resource | Specify the Model Name. Model will be created in app directory. |
--fields | Specify the attributes of the resource, for the migration. This will also set $fillable on the model file. Be sure to check the fields section. |
Creating a Controller
Command: php artisan crud:controller
Description:
This command will create a resource-controller for the resource, with built-in validation and pagination.
It will create the following methods: index
, create
, store
, show
, edit
, update
, destroy
, with corresponding PHPDoc.
Option | Description |
---|---|
Resource | Specify the resource name. The file will be created in app/Http/Controllers |
--fields | Specify the attributes of the resource. This will be used in validation. Be sure to check the fields section. |
--route-prefix | Optional. Specify the route prefix that will be used for the resource, using dot-notation. admin.resources will result in admin/resources/model route. |
--view-path | Optional. Specify the path inside the views folder to the views of the resource, using dot-notation. admin.resources will result in view('admin.resources.model.index') |
Creating views
Command: php artisan crud:view
Description: This command will create the following view-files for the resource. It will also create a master-layout file, that all the views extend.
It will create the following files: create.blade.php
, edit.blade.php
, errors.blade.php
, form.blade.php
, index.blade.php
, scripts.blade.php
, show.blade.php
.
The package uses the Laravel illuminate/html package to create all the form-inputs,
which as of Laravel 5 is no longer included by default in the Laravel framework.
Option | Description |
---|---|
Resource | Specify the resource name. The files will be created in the views-directory. |
--fields | Specify the attributes of the resource. This will be used to create the form. Be sure to check the fields section. |
--route-prefix | Optional. Specify the route prefix that will be used for the resource, using dot-notation. admin.resources will result in admin/resources/model route. |
--view-path | Optional. Specify the path inside the views folder to the views of the resource, using dot-notation. admin.resources will result in view('admin.resources.model.index') |
Notes
When using the --route-prefix and/or the --view-path option, make sure they match on both the controller and the views.
Fields
Here is a list of the fields that are available.
Model/Migration | Views/Controller |
---|---|
string | text |
char | text |
varchar | text |
decimal | text |
float | text |
double | text |
string | password |
string | |
string | date |
string | datetime |
string | datetime |
string | time |
timestamp | timestamp |
text | textarea |
mediumtext | textarea |
longtext | textarea |
json | textarea |
jsonb | textarea |
binary | file |
number | number |
integer | number |
bigint | number |
mediumint | number |
smallint | number |
tinyint | radio |
boolean | radio |