%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/camillo/camillo-api-master/app/Nova/
Upload File :
Create Path :
Current File : /var/www/html/camillo/camillo-api-master/app/Nova/Institute.php

<?php

namespace App\Nova;

use App\Enums\UsertypeEnum;
use App\Nova\Actions\GeneratePDF;
use App\Nova\Actions\StartJob;
use Laravel\Nova\Fields\BelongsToMany;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Panel;

class Institute extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var string
     */
    public static $model = 'App\Models\Institute';

    /**
     * The single value that should be used to represent the resource when being displayed.
     *
     * @var string
     */
    public static $title = 'name';

    public static function label()
    {
        return __('Institutes');
    }

    public static function singularLabel()
    {
        return __('Institute');
    }

    /**
     * The columns that should be searched.
     *
     * @var array
     */
    public static $search = [
        'id', 'name', 'province', 'city'
    ];

    /**
     * Get the fields displayed by the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable()->canSee(function($request){
                return $request->user()->usertype->role === UsertypeEnum::ADMIN;
            })->hideFromIndex(),

            Text::make(__('Name'), 'name')
                ->rules('required')
                ->sortable(),

            Text::make(__('Category'), 'category')
                ->rules('required')
                ->sortable()->hideFromIndex(),

            Text::make(__('Typology'), 'typology')
                ->rules('required')
                ->sortable()->hideFromIndex(),

            Text::make(__('Code'), 'code')
                ->rules('required')->hideFromIndex(),

            Text::make(__('City'), 'city')->sortable(),

            Text::make(__('Province'), 'province')
                ->rules('required', 'size:2')
                ->sortable()->hideFromIndex(),

            Text::make(__('Zip Code'), 'zip_code')
                ->sortable()
                ->rules('required', 'size:5')->hideFromIndex(),

            Text::make(__('Address'), 'address')
                ->rules('required')->hideFromIndex(),

            Text::make(__('Phone'), 'phone')
                ->rules('required'),

            Text::make(__('Email'), 'email')->hideFromIndex()
                ->rules('email')
                ->creationRules('unique:institutes,email')
                ->updateRules('unique:institutes,email,{{resourceId}}'),

            Boolean::make(__('Active'), 'active')->hideFromIndex(),

            BelongsToMany::make(__('Users'), 'users', User::class)

        ];
    }

    /**
     * Get the address fields for the resource.
     *
     * @return array
     */
    protected function addressFields()
    {
        return [

        ];
    }

    /**
     * Get the cards available for the request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function cards(Request $request)
    {
        return [];
    }

    /**
     * Get the filters available for the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function filters(Request $request)
    {
        return [];
    }

    /**
     * Get the lenses available for the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function lenses(Request $request)
    {
        return [];
    }

    /**
     * Get the actions available for the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function actions(Request $request)
    {
        return [
            (new Actions\GenerateQRCode)->canSee(function ($request) {
                return true;
            })->canRun(function ($request, $user) {
                $allowed = [
                    UsertypeEnum::ADMIN,
                    UsertypeEnum::PRINCIPAL
                ];
                return in_array($request->user()->usertype->role, $allowed);
            }),
            (new Actions\GeneratePDF)->canSee(function ($request){
                $allowed = [
                    UsertypeEnum::ADMIN
                ];
                return in_array($request->user()->usertype->role, $allowed);
            })
        ];
    }
}

Zerion Mini Shell 1.0