Support the ongoing development of →
Views Blade
Last updated 1 year ago.

If you're trying to call a controller function from anywhere other than a route, it's usually a sign that you're doing something wrong. Controllers are supposed to just be a transport layer between a HTTP request and your application, after all. And your views should be as "dumb" as possible - no logic other than pure presentation logic, like iterating over an array to build an HTML table. I can think of at least two ways to handle that:

1 - Use a View Composer - specify what section of the nav you're loading in the controller and then use the view composer to add the correct navigation, like so:

class NavigationViewComposer

    protected $sections = array(
        'auctions' => array(
            '/auctions/latest' => 'Latest Auctions',
        'users' => array(
            '/users/you' => 'Your Profile',

    public function compose($view)
        $data = $view->getData();
        $section = isset($data['section']) ? $data['section'] : 'site';
        $view->with('navigation', $this->sections[$section]);


2 - Use partials - Have a different layout (that extends your master layout) for each section, then put the section-specific navigation there. For example:

//file: layouts/auctions.blade.php

<li><a href="/auctions/latest">Latest Auctions</a></li>
<!-- etc -->

Last updated 1 year ago.

Sign in to participate in this thread!


Your banner here too?

pasternt pasternt Joined 7 Feb 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.