0
0
Laravelframework~10 mins

Model creation in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new Laravel model named Post.

Laravel
php artisan make:model [1]
Drag options to blanks, or click blank then click option'
APost
Bpost
CPosts
DpostModel
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase model names like 'post' instead of 'Post'.
Using plural names like 'Posts' which is not standard for models.
2fill in blank
medium

Complete the code to define a model class named Post in Laravel.

Laravel
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class [1] extends Model
{
    // Model code here
}
Drag options to blanks, or click blank then click option'
Aposts
Bpost
CPosts
DPost
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or plural class names which do not follow Laravel conventions.
3fill in blank
hard

Fix the error in the model definition by completing the code.

Laravel
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $[1] = ['title', 'content'];
}
Drag options to blanks, or click blank then click option'
Aguarded
Bfillable
Chidden
Dvisible
Attempts:
3 left
💡 Hint
Common Mistakes
Using guarded instead of fillable when intending to allow mass assignment.
Using hidden or visible which control serialization, not mass assignment.
4fill in blank
hard

Fill both blanks to define a model with a custom table name and timestamps disabled.

Laravel
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
    protected $[1] = '[2]';
    public $timestamps = false;
}
Drag options to blanks, or click blank then click option'
Atable
Barticles_custom
Ctimestamps
Dposts
Attempts:
3 left
💡 Hint
Common Mistakes
Using $timestamps as a property name for the table.
Setting the table name to a wrong or pluralized default name.
5fill in blank
hard

Fill all three blanks to define a model with guarded attributes and a custom primary key.

Laravel
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class UserProfile extends Model
{
    protected $[1] = ['password', 'remember_token'];
    protected $[2] = '[3]';
}
Drag options to blanks, or click blank then click option'
Aguarded
BprimaryKey
Cuser_id
Dfillable
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing fillable and guarded properties.
Not setting the primary key property correctly.