Courses

Vue Laravel 12 Starter Kit: CRUD Project

DB Model, New Vue Page and Menu Item

Summary of this lesson:
- Create Task model, migration, and factory with sample data
- Build controller and routes for CRUD operations
- Set up validation with Form Request classes
- Add Vue navigation menu item with an icon for Tasks

Let's try to create a simple CRUD for Tasks with two fields (for now): name and is_completed.

In this lesson, we'll manage the Model/Migration, Routes, and Controllers and add a navigation link in the top menu.


Preparing the Database

First, we create the DB structure with factories to create some fake records:

php artisan make:model Task -mf

The table structure is in Migration.

database/migrations/xxxx_create_tasks_table.php:

public function up(): void
{
Schema::create('tasks', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->boolean('is_completed')->default(false);
$table->timestamps();
});
}

In the Model, we just make the fields fillable and cast is_completed to boolean.

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
 
class Task extends Model
{
use HasFactory;
 
protected $fillable = [
'name',
'is_completed'
];
 
protected function casts(): array
{
return [
'is_completed' => 'boolean'
];
}
}

Then, the Factory with the...

The full lesson is only for Premium Members.
Want to access all 14 lessons of this course? (82 min read)

You also get:

  • 73 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord