Brands CRUD
Create database table through database migration
In root folder of your project, run the following command in the terminal to create model and migration for `brands` database table.
php artisan make:model Brand -mAdd the following code to the up() function of the brands table migration file.
...
public function up()
{
Schema::create('brands', function (Blueprint $table) {
$table->id();
$table->timestamps();
// column to store image path
$table->string('image')->nullable();
// column to store brand name
$table->string('name')->unique();
// column to specify if brand is active or not
$table->boolean('is_active')->default(true);
// columns for storing created_by, updated_by, craeted_at
// and updated_at
SpeedAdminHelpers::createdByUpdatedByMigrations($table);
});
}
...Run command php artisan migrate to create the "brands" database table.
Add CRUD functionality to Brand Model
Add the following code to Brand.php (model file). See comments in the following code for more information.
Add columns for Grid (datatable):
Add following code to function addGridColumns() . In the following code, we are adding three columns to be shown in the grid (datatable).
Add permissions for Brands (Add/Edit/Delete/List)
Add the following code in the boot() function in AppServiceProvider.php to add permissions related to the brand entity.
Visit localhost:8000/admin/roles/create and you can see the permissions:

Add BrandController
Run the following command in the terminal to create BrandController
Update BrandController.php file as shown below:
Add menu for brands
Add the following code in the boot() function in AppServiceProvider.php to add menu:

Add route for brands
Add route in web.php (routes\web.php).
Now you can click on "Brands" menu to see Grid for Brand entity:

Add Brand Form fields
Add the following code to addFormFields() function in Brand.php (model). All following code is easy to understand.
Now click on "Add New" button in brands page or visit localhost:8000/admin/brands/create. You can see the following form:

Last updated