2

I need call different header for hosting and about pages mentioned below, while executing the below code I'm getting error as "Undefined class constant 'hosting'". suggest me how to solve this and call different headers for various pages.

@if(Route::hosting == 'hosting')
{
  @include('partials.header');
}
@elseif(Route::About == 'About'){
   @include('partials.header1');
}
 @endif
sharmila
  • 175
  • 2
  • 19

3 Answers3

3

Use \Request::is() to check current route, and dont' use {...} inside @if condition, if there is only two condition @if...@else...@endif is enough.

@if(\Request::is("hosting"))
  @include('partials.header');
@else
   @include('partials.header1');
@endif

You can also avoid of using another header partials.header1, If there is not much difference.

Pass a variable named is_hosting as true/false and display contents accordingly..

@if(\Request::is("hosting"))
  @include('partials.header',["is_hosting"=>true]);
@else
  @include('partials.header',["is_hosting"=>false]);
@endif

Inside partials.header

@if(isset($is_hosting) && $is_hosting) 
    header's content
@else
    header1's content
@endif
Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109
0
@if(Route::currentRouteName() == 'hosting') 

    @include('partials.header');

@elseif(Route::currentRouteName() == 'About')

     @include('partials.header1'); 

@endif

use Route::currentRouteName() to get the name of the current route.

Joe
  • 4,618
  • 3
  • 28
  • 35
0

Take a look at this answer:

How to get current route name in laravel 5?

I believe your're confusing how to access the current route name. There's a couple of methods available to access the current route:

Route::getCurrentRoute()->getPath();  // Route path
Request::route()->getName();  // Route Name
$request->path();  // URL
Loek
  • 4,037
  • 19
  • 35