Sometimes you may face a problem like you need to check which name route request is coming from the end users in your application. In this case, there is a simple solution to check incoming naming route requests. So in this tutorial, you will learn how to check specific route in Laravel.

If we want to determine if the current request was routed to a given named route, we may use the named method on a Route instance. For example, we may check the current route name like this:

laravel-check-requested-route-name

Now see the example code of how to get a route name from a request in Laravel.

<?php

public function store(Request $request)
{
  if ($request->route()->named('post.store')) {
     // Laravelia
  }
}

 

Read also: How Many Types Of Routes Are There In Laravel?

 

Conclusion

I have tried to discuss the clear concept of how to check specific route in Laravel. Now we know How to get route name from request in Laravel. Hope this check laravel routes tutorial will help you.

Category : #laravel

Tags : #laravel , #laravel routing