PHP code example of memdev / laravel-frontend-policy

1. Go to this page and download the library: Download memdev/laravel-frontend-policy 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/ */

    

memdev / laravel-frontend-policy example snippets


use Pine\Policy\UsesModelName;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    use UsesModelName;

    protected $appends = ['model_name'];
}
html
@currentUser

<!-- Result -->
<script>window['user'] = { ... };</script>
html
@currentUser ('admin')

<!-- Result -->
<script>window['admin'] = { ... };</script>
sh
php artisan make:js-policy Comment
js
...

view(user, model)
{
    return user.id == model.user_id;
}

create(user)
{
    return user.is_admin;
}

approve(user, model)
{
    return user.is_editor && user.id == model.user_id;
}

...