0
0
Laravelframework~10 mins

MVC architecture 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 define a route that uses the HomeController's index method.

Laravel
Route::get('/', [[1]::class, 'index']);
Drag options to blanks, or click blank then click option'
AController
Bweb
CRoute
DHomeController
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'web' instead of the controller name.
Using 'Route' or 'Controller' which are not controller class names.
2fill in blank
medium

Complete the code to create a new controller named ProductController using Artisan command.

Laravel
php artisan make:[1] ProductController
Drag options to blanks, or click blank then click option'
Amigration
Bmodel
Ccontroller
Dseeder
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'model' or 'migration' which create different classes.
Using 'seeder' which is for database seeding.
3fill in blank
hard

Fix the error in the controller method to return a view named 'welcome'.

Laravel
public function index() {
    return [1]('welcome');
}
Drag options to blanks, or click blank then click option'
Aview()
BView()
Creturn()
Drender()
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase 'View()' which causes an error.
Using 'return()' or 'render()' which are not correct here.
4fill in blank
hard

Fill both blanks to pass data from controller to view with variable 'name' set to 'Laravel'.

Laravel
return view('greeting', [[1] => [2]]);
Drag options to blanks, or click blank then click option'
A'name'
B'Laravel'
C'view'
D'data'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without quotes.
Swapping key and value positions.
5fill in blank
hard

Fill all three blanks to define a model named Post with a fillable property for 'title' and 'content'.

Laravel
class [1] extends Model {
    protected $[2] = [[3]];
}
Drag options to blanks, or click blank then click option'
APost
Bfillable
C'title', 'content'
Dtimestamps
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'timestamps' instead of 'fillable'.
Not quoting the array elements properly.