Skip to content

alfonsobries/laravel-data-bags

 
 

Repository files navigation

Laravel Data Bags

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

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.

Installation

composer require konceiver/laravel-data-bags

Usage

Registration & Resolving

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');
});

Blade Component

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.

Register bag

use Konceiver\DataBags\DataBag;

DataBag::register('meta', [
    '/' => [
        'title'       => 'My Website',
        'description' => 'Posts, Media & More',
    ],
]);

Route::get('home', function ($id) {
    return view('home');
});

Create metatag component

<meta property="og:title" content="{{ $title }}" />
<meta property="og:description" content="{{ $description }}">

Include data bag component

<x-data-bag key="meta" resolver="path" view="components.meta" />

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

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.

Credits

This project exists thanks to all the people who contribute.

Support Us

We invest a lot of resources into creating and maintaining our packages. You can support us and the development through GitHub Sponsors.

License

Laravel Data Bags is an open-sourced software licensed under the MIT.

Packages

No packages published

Languages

  • PHP 100.0%