Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check Route Prefix in Blade If Loop

Tags:

php

laravel

I have a route defined like such:

Route::get('aanmelden/{companySlug}/{packageSlug}', ['as' => 'register', 'uses' => 'UsersController@create'])

I want to display some extra plug-in on this specific page, so in the header I want an if loop that checks for the prefix 'register' to display the code.. No luck yet. I tried this:

@if(Request::is('register'))

@if(Request::path() == 'aanmelden')
like image 478
Anna Jeanine Avatar asked Dec 29 '25 05:12

Anna Jeanine


1 Answers

If you want to check route name, do something like this:

@if (Route::currentRouteName() === 'register')

If you want to check if route name starts with register (so it's like prefix), use starts_with() helper:

@if (starts_with(Route::currentRouteName(), 'register'))
like image 104
Alexey Mezenin Avatar answered Dec 30 '25 21:12

Alexey Mezenin