Next up we have @bobbybouwmann who will be talking about Laravel Router.

Thread ๐Ÿงต
And now he's updating Zoom in the background ๐Ÿ˜‚
That's a good menu
We'll be spending most of the time here in web.php
Different options in Laravel to register routes.

Multiple routes for "one" resource.

Different HTTP methods available. We can reuse same URI but with different methods.

route:list command output

with --compact option
Route::resource() method. It is a time saver but its also PITA if you need fewer methods/routes from it.
There's also a way to handle with above situation using only() and except() methods.

Downside of this method is if you want to see all the routes, you will need to run route:list command. You can't tell by looking at Route::resource in web.php file
Other options like prefix, middleware, domain. You can also put these in a group so the options apply to all routes in a group.

Groups can also be nested. New groups with different conditions.

route:list command also accepts options to display on the table.
Every route has a middleware called web. But we didn't apply it anywhere inside web.php file.

RouteServiceProvider located in app/Providers.

In previous versions ( <8) of Laravel ) we needed to provide $namespace property on provider.

boot method applies 'web' middleware.
Route::match method, accept multiple HTTP methods based on the method being posted.
Route::redirect() and Route::permanentRedirect()

These are handled by RoutingController , woah, didn't know this.

Route::view() is also handled by a Controller.

Route::fallback() method can be used to provide a fallback url if none route matches. It should be at the end.
Route names

You can change the URI but since the name is still. same you don't need to change it everywhere else.

Pass arguments to route() helper method when using route names.

Adding extra parameters "will break" the route.

redirect to certain route using its name
Route::current()

Route::currentRouteName();

Route::currentRouteAction();

Some other helpful methods on Route class.
How do we get from Request to Response?

P.S.

Is Pizza coming? ๐Ÿ‘€
First file that request touches is index.php,

From there it goes to Kernel.php

Some middlewares are being registered.

First array of middlewares are applied on all requests.

middlewareGroups apply on grouped routes.
Looking handle method of HttpKernel inside laravel/framework.

handle method does one thing, send response to request.

First sendRequestThroughRouter

Resolve 'request' and then call $this->bootstrap()

Part of booting, RouteServiceProvider is booted and routes() method is calld
If routesAreCached using the route:cache command, load all the routes from there. Otherwise load the routes.

Digging more into loadRoutes()

It will call all those methods when we do $this->app->call

Generic action for all routes in las screenshot.
where statements can be seen being applied at the end.

prefixes are being applied.

Now that routes are loaded, last method calls to refreshNameLookups register the name of routes and also a method for Actions.
Next is the Pipeline ( interesting stuff )

Request is being passed through middlewares.

Request is being bind again in dispatchToRouter as it has been modified.

We first findRoute and then runRoute

match() method gives the first route that matches.
matchAgainstRoutes() method, which loops over all routes and checks for fallback first.

Laravel routing depends on SymfonyRoute which at the end finds the "route".

Damn, that's a lot of things happening. Hard to keep up ๐Ÿ˜‚
First we bind current request to route. NotFoundHttpException if route is not found.

if we found the route, we put it in Container.

Then we go to runRoute() after that runRouteWithinStack , "onion" instance.

That's a lot of layers.
prepareResponse method is responsible for preparing the response that needs to be sent.

That's a lot happening in `toResponse()` method ... :mind_blow:
RequestHandled event. You can use it do something you want like, how many Requests handled by your app.
Route Model Binding.

@bobbybouwmann really miss Airpots I think ๐Ÿ˜…

if we don't type-hint in the route, Laravel wouldn't know.

Then we have ->where conditions in our rates.

Some extra methods like whereUuid, whereAlphaNumeric on Route class.
Route::missing() callback

DID NOT KNOW ABOUT IT.

Specify column name which should be queried for Route Model Binding.

We can specify queries inside RouteServiceProvider for Route Model Binding Query.
Substitute bindings

The query for binding inside boot method of RouteServiceProvider
RouteBinding forModel() method.

Explicit Binding first and then Implicit Binding.

What goes on inside Implicit Binding and RouteSignatureParameters.

Laravel uses Reflection to grab all parameters and what params are potentially models and if they should be retreived from DB.
Every Model class implements UrlRoutable interface.

Also some references to ChildRoutes.
First we get the Controller class and method on it against the dispatch method of ControllerDispatcher.

Inside 'dispatch' method, all dependencies of Controller class and methods are resolved from Container.
We can use re-use logic from SymfonyRouter especially the "regex" part.

Magic happens in getRouteParametersForPattern

Compiling the Route and match the regex with certain parameters and return it.
Some best practices about writing routes by @bobbybouwmann
Best practices continued,

parameters based routes should be below.

use route caching in production, make sure you don't use it locally.
End of talk by @bobbybouwmann

P.S.

No pizza for me ๐Ÿ˜ญ

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Zubair Mohsin

Zubair Mohsin Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Zubairmohsin33

17 Mar
Next up we have @enunomaduro on @LaraconOnline

He'll be telling us about Artisan Console Component

Thread ๐Ÿงต
Image
Few projects of Nuno running on Artisan console component. ImageImage
Read 19 tweets
17 Mar
Next up we have @calebporzio talking about @LaravelLivewire and @Alpine_JS

Thread ๐Ÿงต Image
of Livewire. Woah! ImageImageImage
Show the small things, instead of big things.

Shoutout to @TransistorFM and @noplanstomerge Image
Read 26 tweets
17 Mar
Next up we have @m1guelpf on @LaraconOnline

He'll be talking about Laraveil Illuminate Foundation

Thread ๐Ÿงต
laravel/framework requires micro packages namespaced under Illuminate.
Read 17 tweets
17 Mar
Next up we have @marcelpociot

He'll be talking about Laravel Broadcasting on @LaraconOnline

Thread ๐Ÿงต
Follow along at laracon.beyondco.de

It contains some interactive examples.
Two components involved in Broadcasting. Just the communication between Laravel Backend

Everytime you shoot the shoot button confetti's happen in real-time. ( laracon.beyondco.de )
Read 25 tweets
17 Mar
Next up, we have @taylorotwell on @LaraconOnline

Thread about keynotes from Taylor's talk.

๐Ÿงต
Thanking everyone ๐Ÿ˜…
Stupid internet got disconnected. Alright, we are back on.
Read 38 tweets
17 Mar
Next up is @christophrumpel talking about Service Container.

Thread ๐Ÿงต
Cool animation on slides.
Dinner break ๐Ÿ˜” can't live-tweet ... Just listening ๐Ÿ˜…
Read 21 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!