- Which of the following code snippets demonstrates how to define a route with a middleware in Laravel?
Route::get('/admin/dashboard', 'DashboardController@index')->middleware('auth');
A) Option A: Defines a route for the admin dashboard accessible only to authenticated users.
B) Option B: Defines a route for the user dashboard accessible only to authenticated users.
C) Option C: Defines a route for the admin dashboard accessible to both authenticated and guest users.
D) Option D: Defines a route for the user dashboard accessible to both authenticated and guest users.
Answer: A) Option A
- Which of the following code snippets demonstrates how to define a route parameter with a regular expression constraint in Laravel?
Route::get('/posts/{post}', function ($post) { return Post::findOrFail($post); })->where('post', '[0-9]+');
A) Option A: Defines a route for fetching a specific post by its ID.
B) Option B: Defines a route for fetching a specific post by its slug.
C) Option C: Defines a route for fetching a specific post by its title.
D) Option D: Defines a route for fetching a specific post by its category.
Answer: A) Option A
- Which of the following code snippets demonstrates how to define a route with a middleware assigned using the controller's constructor in Laravel?
Route::middleware('auth')->group(function () {
Route::get('/dashboard', 'DashboardController@index');
Route::get('/profile', 'ProfileController@show');
});
A) Option A: Defines a route for the user dashboard accessible only to authenticated users.
B) Option B: Defines a route for the admin dashboard accessible only to authenticated users.
C) Option C: Defines a route for the user profile accessible only to authenticated users.
D) Option D: Defines a route for the admin profile accessible only to authenticated users.
Answer: B) Option B
- Which of the following code snippets demonstrates how to define a route with parameter binding in Laravel?
Route::get('/users/{user}', function (App\Models\User $user) { return $user; });
A) Option A: Defines a route for fetching a user's profile by their username.
B) Option B: Defines a route for fetching a user's profile by their email.
C) Option C: Defines a route for fetching a user's profile by their ID.
D) Option D: Defines a route for fetching a user's profile by their role.
Answer: C) Option C
- Which of the following code snippets demonstrates how to define a route with a custom controller method in Laravel?
Route::get('/posts', 'PostController@customMethod');
A) Option A: Defines a route for fetching all posts.
B) Option B: Defines a route for creating a new post.
C) Option C: Defines a route for updating a post.
D) Option D: Defines a route for deleting a post.
Answer: A) Option A
Comments