PHP code example of lupennat / preview

1. Go to this page and download the library: Download lupennat/preview 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/ */

    

lupennat / preview example snippets



use Illuminate\Support\Str;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Lupennat\Preview\Preview;

class Post extends Resource
{

    public function fields(Request $request)
    {
        return [
            Preview::make(__('Title'), 'title')->when(
                fn($value, $resource, $attribute) => strlen($value) > 20 ? Str::limit($value, 20) : false,
                Text::make(__('Title'), 'title')
            )
        ];
    }
}


use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Lupennat\Preview\Preview;

class Post extends Resource
{

    public function fields(Request $request)
    {
        return [
            Preview::make(__('Description'), 'description')
                ->is(Text::make(__('Description'), 'description'))
                ->withPreviewLabel(__('View Description'))
        ];
    }
}