Не выдержал и решил проверить это дело кодом.
PHP 7.3.3, Laravel 5.8
Миграция:
class CreateTestTable extends Migration
{
public function up()
{
Schema::create('test', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->nullable();
$table->integer('age')->nullable();
$table->timestamps();
});
}
}
Модель:
class Test extends Model
{
protected $table = 'test';
protected $guarded = [];
}
Вывод php artisan tinker
Psy Shell v0.9.9 (PHP 7.3.3 — cli) by Justin Hileman
>>> use App\Models\Test;
>>> Test::create(['age'=>'21','name'=>'Ivan']);
=> App\Models\Test {#2985
age: "21",
name: "Ivan",
updated_at: "2019-08-27 12:44:11",
created_at: "2019-08-27 12:44:11",
id: 1,
}
Убираем guard у модели:
class Test extends Model
{
protected $table = 'test';
}
tinker:
Psy Shell v0.9.9 (PHP 7.3.3 — cli) by Justin Hileman
>>> use App\Models\Test;
>>> Test::create(['age'=>'24','name'=>'Ivan3']);
Illuminate/Database/Eloquent/MassAssignmentException with message 'Add [age] to fillable property to allow mass assignment on [App/Models/Test].'