0

I want to check if the current route isn't equal to a specific route in laravel view. How can I do that in Blade ?

my attempt:

 @if(Route::current() != Route('places.show'))
     <td><a href="/admin/places/display/{{$order->place->id}}">{{ $order->place->name }}</a></td>
 @endif
Fateh Alrabeai
  • 660
  • 3
  • 17
  • 35
  • You can get the current url in blade as url()->current() and then you can compare it. – Vikash Dhiman Dec 30 '19 at 06:58
  • Does this answer your question? [How to Get the Current URL Inside @if Statement (Blade) in Laravel 4?](https://stackoverflow.com/questions/17591181/how-to-get-the-current-url-inside-if-statement-blade-in-laravel-4) – Chonchol Mahmud Dec 30 '19 at 06:59

2 Answers2

4

Laravel Routes has method to get it.

To get current route name:

Illuminate\Support\Facades\Route::currentRouteName();

To check the current route is a matching route:

Illuminate\Support\Facades\Route::is('routename');
halfer
  • 19,824
  • 17
  • 99
  • 186
ManojKiran A
  • 5,896
  • 4
  • 30
  • 43
2

You can call the currentRouteName on the route class.

Route::currentRouteName();

Don't forget to use the class:

use Illuminate\Support\Facades\Route;

To Check the current route:

Illuminate\Support\Facades\Route::is('routename');
Shantha Kumara
  • 3,272
  • 4
  • 40
  • 52