Bird
0
0

Which syntax correctly shows how to define a route in Laravel using a closure?

easy📝 Syntax Q12 of 15
Laravel - Basics and Architecture
Which syntax correctly shows how to define a route in Laravel using a closure?
A<code>Route::get('/home', function () { return 'Home'; });</code>
B<code>route->get('/home', function () { return 'Home'; });</code>
C<code>Route.get('/home', () => 'Home');</code>
D<code>Route::get('/home', 'HomeController@index');</code>
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct Laravel route syntax

    Laravel uses the static method call syntax with double colons, like Route::get().
  2. Step 2: Check each option

    Route::get('/home', function () { return 'Home'; }); uses correct syntax with a closure function. route->get('/home', function () { return 'Home'; }); uses wrong arrow syntax. Route.get('/home', () => 'Home'); uses dot notation which is invalid. Route::get('/home', 'HomeController@index'); is valid Laravel syntax but requires a controller method, not a closure.
  3. Final Answer:

    Route::get('/home', function () { return 'Home'; }); -> Option A
  4. Quick Check:

    Laravel routes use Route::get() with closures [OK]
Quick Trick: Laravel routes use Route::get() with double colons [OK]
Common Mistakes:
  • Using dot notation instead of ::
  • Using lowercase 'route' instead of 'Route'
  • Confusing closure and controller syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes