php - Laravel 5, calling function inside compose@ViewComposer logs fatal error and returns result as expected -
i trying route name
app('request')->route()->getname();
inside compose method of view composer called boot method of serviceprovider.
the result returns expected (foo.create etc.) but, when check log files,
laravel 5 logs,
exception 'symfony\component\debug\exception\fatalerrorexception' message 'call member function getname() on null'
and can't understand how can undefined function return right object , can call method on it.
any appreciated. thanks.
i got current route's name in different way , did not see in logs, maybe try this:
public function boot() { view()->composer([...], function($view){ dd(\route::currentroutename());
about error, i'd guess ->route()
returning null, hence error, laravel sends getname()
message app('request')
works. can try app('request')->getname();
or app('route')->getname();
Comments
Post a Comment