Skip to content

Latest commit

 

History

History
29 lines (25 loc) · 591 Bytes

laravel_steps_crud.md

File metadata and controls

29 lines (25 loc) · 591 Bytes

Steps for a CRUD feature in Laravel

Generate model, migration, factory, and seed

php artisan make:model ModelName -mfs

Add columns in the migration

Schema::create('model_name', static function (Blueprint $table) {
    $table->id();
    $table->foreignId('model_name_id')->constrained();
    $table->string('value');
    $table->timestamps();
});

Add fillable values and relationships in the model

protected $fillable = [
    'model_name_id',
    'value',
];

public function attribute(): BelongsTo
{
    return $this->belongsTo(ModelName::class);
}