PHP code example of novius / laravel-nova-contexts

1. Go to this page and download the library: Download novius/laravel-nova-contexts library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

novius / laravel-nova-contexts example snippets




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(),
        ];
    }
}




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

public function fields(Request $request)
{
    return [
        // ...
        
        ContextField::make('locale'),
        
        // ...
    ];
}

/**
 * Get the filters available for the resource.
 *
 * @param \Illuminate\Http\Request $request
 * @return array
 */
public function filters(Request $request)
{
    return [
        new ContextFilter($this->model()),
    ];
}
sh
php artisan vendor:publish --provider="Novius\LaravelNovaContexts\LaravelNovaContextsServiceProvider" --tag="config"