This package was created by, and is maintained by Brian Faust, and provides an easy way of storing generic data that is resolved based on the location.
composer require konceiver/laravel-data-bags
use Konceiver\DataBags\DataBag;
DataBag::register('meta', [
'users' => ['title' => 'Users'],
'*' => ['title' => 'Placeholder'],
]);
Route::get('users', function ($id) {
// This will return ['title' => 'Users']
return DataBag::resolveByPath('meta');
});
Route::get('/', function ($id) {
// This will return ['title' => 'Placeholder']
return DataBag::resolveByPath('meta');
});
For convenience we offer a Blade component that will make it easy for you to include resolved data into views. We'll use meta tags as an example.
use Konceiver\DataBags\DataBag;
DataBag::register('meta', [
'/' => [
'title' => 'My Website',
'description' => 'Posts, Media & More',
],
]);
Route::get('home', function ($id) {
return view('home');
});
<meta property="og:title" content="{{ $title }}" />
<meta property="og:description" content="{{ $description }}">
<x-data-bag key="meta" resolver="path" view="components.meta" />
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover a security vulnerability within this package, please send an e-mail to security@konceiver.dev. All security vulnerabilities will be promptly addressed.
This project exists thanks to all the people who contribute.
We invest a lot of resources into creating and maintaining our packages. You can support us and the development through GitHub Sponsors.
Laravel Data Bags is an open-sourced software licensed under the MIT.