This package allows you to manage resource contexts.
It provides :
- Default context choice during back-office navigation (on nova card).
- Context filter bases on default context.
- Context field for resources.
- PHP >= 8.0
- Laravel Nova >= 4.0
NOTE: These instructions are for Laravel Nova >= 4.0. If you are using prior version, please see the previous version's docs.
composer require novius/laravel-nova-contexts
Some options that you can override are available.
php artisan vendor:publish --provider="Novius\LaravelNovaContexts\LaravelNovaContextsServiceProvider" --tag="config"
A card is available to navigate between contexts. You can easily add it to custom resource index.
<?php
namespace App\Models;
use Laravel\Nova;
use Novius\LaravelNovaContexts\LaravelNovaContexts;
class Page extends Resource
{
// Some resources definitions...
public function cards(Request $request)
{
return [
(new LaravelNovaContexts())->dynamicHeight(),
];
}
}
To make a model "contextable", just use HasContext
trait.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Novius\LaravelNovaContexts\Traits\HasContext;
class Page extends Model
{
use HasContext;
/**
* @return string
*/
public function contextFieldName(): string
{
return 'locale';
}
}
You can add context field to your Nova resource's fields:
public function fields(Request $request)
{
return [
// ...
ContextField::make('locale'),
// ...
];
}
You can add context filter to your Nova resource's filters :
/**
* Get the filters available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function filters(Request $request)
{
return [
new ContextFilter($this->model()),
];
}
Run php-cs with:
composer run-script lint
Contributions are welcome!
Leave an issue on Github, or create a Pull Request.
This package is under GNU Affero General Public License v3 or (at your option) any later version.