Set Columns To Prevent Mass Assignable in Laravel
To set the columns to prevent mass assignable in Laravel you can "guard" it using the code example below.
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Post extends Model { /** * The attributes that are mass assignable. * * @var array */ protected $guarded = ['name', 'slug', 'content', 'pubilshed_at']; }
Unguard Columns To Allow Mass Assignable in Laravel
To unguard and allow all columns to be mass assignable you can make use of the wildcard symbol.
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Post extends Model { /** * The attributes that are mass assignable. * * @var array */ protected $guarded = ['*']; }
Leave a reply