Closed tsndp closed 4 years ago
This is now unchanged. Same as the previous package
For example, route definition
// routes/web.php
Route::resource('photo', PhotoController::class);
And the explicit indication of breadcrumbs:
// Any service provider
// Photos
Breadcrumbs::for('photo.index', fn (Trail $trail) =>
$trail->parent('home')
->push('Photos', route('photo.index'))
);
// Photos > Upload Photo
Breadcrumbs::for('photo.create', fn (Trail $trail) =>
$trail->parent('photo.index')
->push('Upload Photo', route('photo.create'))
);
// Photos > [Photo Name]
Breadcrumbs::for('photo.show', fn (Trail $trail, Photo $photo) =>
$trail->parent('photo.index')
->push($photo->title, route('photo.show', $photo->id))
);
// Photos > [Photo Name] > Edit Photo
Breadcrumbs::for('photo.edit', fn (Trail $trail, Photo $photo) =>
$trail->parent('photo.show', $photo)
->push('Edit Photo', route('photo.edit', $photo->id))
);
this we can not do in routes file? we need to maintain another location
Route files are cached, so after running the php artisan route:cache
command, they will not be executed. Dave James Miller package just does use PHP function require in the service provider.
You can easily repeat this:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class BreadcrumbsServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
require base_path('routes/breadcrumbs.php');
}
}
Then it will be your special file in the route directory:
// routes/breadcrumbs.php
// Photos
Breadcrumbs::for('photo.index', fn (Trail $trail) =>
$trail->parent('home')
->push('Photos', route('photo.index'))
);
How to define and how will it render. please include in Readme.