Complete the code to create a new Laravel model named Post.
php artisan make:model [1]The command php artisan make:model Post creates a new model named Post following Laravel naming conventions.
Complete the code to define a model class named Post in Laravel.
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class [1] extends Model { // Model code here }
Model class names in Laravel use PascalCase and should match the model file name. So Post is correct.
Fix the error in the model definition by completing the code.
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Post extends Model { protected $[1] = ['title', 'content']; }
guarded instead of fillable when intending to allow mass assignment.hidden or visible which control serialization, not mass assignment.The $fillable property defines which attributes can be mass assigned in Laravel models.
Fill both blanks to define a model with a custom table name and timestamps disabled.
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Article extends Model { protected $[1] = '[2]'; public $timestamps = false; }
$timestamps as a property name for the table.The $table property sets a custom table name. Here, articles_custom is the custom table name.
Fill all three blanks to define a model with guarded attributes and a custom primary key.
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class UserProfile extends Model { protected $[1] = ['password', 'remember_token']; protected $[2] = '[3]'; }
fillable and guarded properties.The $guarded property protects attributes from mass assignment. The $primaryKey property sets a custom primary key, here user_id.