https://github.com/litstack/meta
A package to easily add meta for crud models and forms.
https://github.com/litstack/meta
Last synced: 3 months ago
JSON representation
A package to easily add meta for crud models and forms.
- Host: GitHub
- URL: https://github.com/litstack/meta
- Owner: litstack
- Created: 2021-02-21T22:34:47.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-04-14T12:19:00.000Z (9 months ago)
- Last Synced: 2025-06-03T20:08:42.410Z (8 months ago)
- Language: PHP
- Homepage:
- Size: 712 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/funding.yml
Awesome Lists containing this project
README
# Litstack Meta
Edit default meta-fields inside your crud-models and forms and receive them in your blade templates.
## Installation
The package can be installed via composer and will autoregister.
```bash
composer require litstack/meta
```
You can now publish and migrate the migration for your meta model:
```shell
php artisan vendor:publish --provider="Litstack\Meta\MetaServiceProvider" --tag=migrations
php artisan migrate
```
## Usage
Start by perparing your Crud-Model by using the `HasMeta` Trait and implement the `metaable` Contract:
```php
use Litstack\Meta\Metaable;
use Litstack\Meta\Traits\HasMeta;
class Post extends Model implements Metaable
{
use HasMeta;
}
```
In order to display the form in litstack edit your model-config:
```php
public function show()
{
$page->card(function($form) {
$form->seo();
});
}
```
To display the meta-fields in your template, simply use the `` component and pass it the `metaFields` of your model.
```php
@extends('app')
@section('meta')
@endsection
```
And in your main template:
```php
@yield('meta')
```
## Default Values / Customizing / Overriding
If you want to use meta attributes directly from model attributes you can specify them in `metaAttributes` in your config. You may as well override the meta methods like `metaAuthor` to return dynamic meta attributes:
```php
class Post extends Model implements Metaable
{
use HasMeta;
protected $metaAttributes = [
'author' => 'author.name',
'image' => 'header_image',
];
public function getHeaderImageAttribute()
{
// ...
}
public function metaTitle(): ?string
{
// Return a prefix:
return "Awesome Blog: " . parent::metaTitle();
}
}
```
You may set default attributes by setting `defaultMetaAttributes` or add a method `defaultMeta...` method:
```php
class Post extends Model implements Metaable
{
use HasMeta;
protected $defaultMetaAttribute = [
'description' => 'description',
];
public function defaultMetaTitle()
{
}
}
```