Why is a function necessary in Route::get?

Posted 1 month ago by davestead

I'm watching Laracasts, Laravel from Scratch, and the narrator shows the call in routes/web.php, as:

Route::get('/', function () { return view('welcome'); });

What I'm not understanding is why a function was determined to be the best thing to be in the 2nd param, as opposed to just specifying a view string.

My PHPStorm editor can't find the get function, or the Route class for some reason when I hover over or Ctrl+click them.

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.