7 months ago

Conditionally show blade view

Posted 7 months ago by oliverbusk

I have below app.blade.php template:

<!-- Sidebar Area -->
@if (\Request::is('*/fields*'))

<!-- Content area -->

As you can see, up until now I have used below condition, to check whether a specific sidebar should be shown:

@if (\Request::is('*/fields/*'))

Above simply checks if the route contains the fields routes, as defined below:

Route::resource('streams/{stream}/fields', 'Stream\FieldsController');

Now, I've reached a point where I need to use this sidebar on another route resource:

Route::resource('streams/{stream}/documents', 'Stream\DocumentsController');

I could just add this to my if statement:

@if (\Request::is('*/fields*') or \Request::is('*/documents*')) 

However, I suppose down the road that I would need to add even more routes to this statement.

What would be the best approach to this? Would it be possible to maybe declare this in the controller or maybe even the model? Something like:

 * Specifies whether the editor menu should be shown or not.
 * @return bool

$sidebarEditor = true;

However, I am a bit unsure about how to implement this - or if there is a better approach?

Please sign in or create an account to participate in this conversation.