Mike Barwick
Mike Barwick

Reputation: 5367

Laravel - View composer with controller method?

Is there a way to return the response of a controller method in a view composer function? This is currently returning a string, the namespace.

view()->composer('tasks.partial.tasksummary', function($view)
{
    $view->with('taskload', 'App\Http\Controllers\TaskController@taskLoad');
});

or... would it be better to just inject the method in my partial directly (via @inject('..'))?

Upvotes: 1

Views: 1103

Answers (1)

Joel Hinz
Joel Hinz

Reputation: 25404

That sounds like something better suited for e.g. a task model. But you could do:

$taskload = (new App\Http\Controllers\Taskcontroller)->taskLoad(); 
$view->with('taskload', $taskload);

Upvotes: 1

Related Questions