PHP code example of zareismail / flexi

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

    

zareismail / flexi example snippets


use App\Models\Post;

/**
 * Resolve the resource for the incoming request.
 */
public function resolve(FlexiRequest $request)
{
    $this->post = Post::findByUri($request->segment(1));

    abort_unless($this->post, 404);
}



namespace App\Flexi\Widgets;

use Flexi\Widgets\Widget;

class PostDetail extends Widget
{
    /**
     * Resolve the widget data.
     */
    public function resolve($resource)
    {
        $this->post = $resource->post;
    }

    /**
     * Get the evaluated contents of the widget.
     *
     * @return string
     */
    public function render()
    {
        return view('post', $this->post);
    }
}

/**
 * Get the widgets available on the entity.
 *
 * @return array
 */
public function widgets(Request $request)
{
    return [ 
        PostDetail::make('Post Detail'),
    ];
}

/**
 * Get the widgets available on the entity.
 *
 * @return array
 */
public function widgets(Request $request)
{
    return [ 
        PostDetail::make('Post Detail')->canSee(fn ($request) => $request->user()->can('viewPost', $request->resolveResource()->post)),
    ];
}
bash
php artisan flexi:resource Post
bash
php artisan flexi:widget PostDetail