Make Columns Fillabe In Laravel
To make the columns fillable you can specify the "$fillable" property like below.
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Post extends Model { /** * The attributes that are mass assignable. * * @var array */ protected $fillable = ['name', 'slug', 'content', 'pubilshed_at']; }
<?php protected $fillable = ['name', 'slug', 'content', 'pubilshed_at'];
Create and Update Laravel Model
So now you can write your "create" and "update" code like the following.
<?php use App\Models\Post; $post = Post::create([ 'name' => 'Post 1 Here', 'slug' => 'post-1-here', 'content' => 'Your post 1 content here', 'published_at' => now() // using carbon helper ]); // Let's assume the code above having ID of 1
<?php use App\Models\Post; // Get the 1st post $post = Post::find(1); $post->update([ 'name' => 'Post 1 UPDATED', 'slug' => 'post-1-here', 'content' => 'Your post 1 content UPDATED' ]);