PHP code example of fragkp / laravel-route-breadcrumb
1. Go to this page and download the library: Download fragkp/laravel-route-breadcrumb library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fragkp / laravel-route-breadcrumb example snippets
Route::get('/')->breadcrumb(YourCustomTitleResolver::class);
class YourCustomTitleResolver
{
public function __invoke()
{
return 'Your custom title';
}
}
Route::get('/foo/{id}')->breadcrumb([app('my_breadcrumb_resolver'), 'resolve']);
// my_breadcrumb_resolver
class MyBreadcrumbResolver
{
public function resolve($id)
{
$title = $this->repo->findById($id);
return $title->getName();
}
}
Route::get('/{foo}')->breadcrumb(YourCustomTitleResolver::class);
class YourCustomTitleResolver
{
public function __invoke(Foo $foo)
{
return "Title: {$foo->title}";
}
}
app(Breadcrumb::class)->links(); // or use here the facade
// app/Providers/AppServiceProvider.php
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
View::composer('your-view', function ($view) {
$view->with('breadcrumb', app(Breadcrumb::class)->links());
});
}
}