Add crud item to Laravel 8.* + Backpack admin
In order to proceed you should have:
- Laravel installed + Backpack admin (teaching purposes)
- virtual host ready for you
- xampp setup or other web server
- composer installed
# STEP 1. create migration
php artisan make:migration:schema create_tags_table — model=0 — schema=”name:string:unique,slug:string:unique”
above won’twork
but
php artisan make:migration create_tags_table
The command above creates a migration file for you. It has two important methods -> up and down.
Schema::create(‘tags’, function (Blueprint $table) {
$table->id();
$table->string(‘name’)->unique();
$table->string(‘slug’)->unique();
$table->timestamps();
});
In Laravel you could describe a table using code.
In the snippet above we are going to create two extra columns ->
name and slug, both of them will be string (varchar)
both of them will have unique index.
php artisan migrate
In order to run a migration you need to run the command above ^
This will create a table for us.
If you want to revert a migration you should run
php artisan migrate:rollback
Ok, we have managed to run and revert a migration. Lets run it again:
php artisan migrate
Now, we have the table created. Next step will be to create CRUD.
# STEP 2. create crud
php artisan backpack:crud tag
After running command we have now:
- controller created for us
- model
- request
- views are updated
- route rules are updated
We have now a fully working CRUD.