Here’s an interesting use of a view composer that’s useful for invoking functions in blade. Create and register a service provider…
php artisan make:provider Composer
In its boot()
method…
public function boot()
for all blade instances…
view()->composer('*', function ($view)
{
declare a function…
$view->with('briefTime', function ($x)
return strrev(substr(strrev($x), 3));
}); }); }
This example defines a way to quickly remove seconds from SQL datetime.
to support the following blade syntax…
<div class="pr-5">{{$briefTime($survey['started_at'])}}</div>