%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/Individual.php

<?php

namespace App\Nova;

use App\Enums\LanguageEnum;
use App\Enums\UsertypeEnum;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\BelongsToMany;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;

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

    /**
     * Get the value that should be displayed to represent the resource.
     *
     * @return string
     */
    public function title()
    {
        return ucfirst($this->name) . " " . ucfirst($this->surname);
    }

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

    public static $with = [
        'user'
    ];

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

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

    public static function relatableQuery(NovaRequest $request, $query)
    {
        if ($request->resource === 'minors' && $request->field === 'individuals') {
            return $query->whereHas(
                'user', function ($u) {
                $u->whereHas(
                    'usertype', function ($q) {
                    $q->where('role', UsertypeEnum::TUTOR);
                }
                );
            }
            );
        }
    }

    /**
     * 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;
            }),

            BelongsTo::make(__('User*'), 'user', User::class)
                ->creationRules('unique:individuals,user_id')
                ->updateRules('unique:individuals,user_id,{{resourceId}}'),

            Text::make(__('Email'), 'email')
                ->sortable()
                ->rules('required', 'email', 'max:254')->hideFromIndex(),

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

            Text::make(__('Surname*'), 'surname')
                ->creationRules('required')
                ->sortable(),

           /* Date::make(__('Birth Date'), 'birth_date')->format('D-M-Y')
                    ->creationRules('date'),*/

            Text::make(__('Fiscal Code*'), 'fiscal_code')
                ->rules('regex:/^(?:(?:[B-DF-HJ-NP-TV-Z]|[AEIOU])[AEIOU][AEIOUX]|[B-DF-HJ-NP-TV-Z]{2}[A-Z]){2}[\dLMNP-V]{2}(?:[A-EHLMPR-T](?:[04LQ][1-9MNP-V]|[1256LMRS][\dLMNP-V])|[DHPS][37PT][0L]|[ACELMRT][37PT][01LM])(?:[A-MZ][1-9MNP-V][\dLMNP-V]{2}|[A-M][0L](?:[1-9MNP-V][\dLMNP-V]|[0L][1-9MNP-V]))[A-Z]$/i')
                ->creationRules('required', 'size:16', 'unique:individuals,fiscal_code')
                ->updateRules('unique:individuals,fiscal_code,{{resourceId}}')->resolveUsing(function ($fiscal_code) {
                    return strtoupper($fiscal_code);
                }),

            Text::make(__('Mobile'), 'phone')
                ->rules( 'nullable','regex:/^(\+\d{1,3}[- ]?)?\d{6,}$/'),

            Text::make(__('Emergency Mobile'), 'mobile')
                ->rules('nullable','regex:/^(\+\d{1,3}[- ]?)?\d{6,}$/')->hideFromIndex(),

            Select::make(__('Language'), 'language')->options([
                LanguageEnum::ITALIAN => "Italiano",
                LanguageEnum::ENGLISH => "Inglese"
            ])->displayUsingLabels()->hideFromIndex(),

            Boolean::make(__('Show Contacts'), 'show_contacts')->hideFromIndex(),

            BelongsToMany::make(__('Minors*'), 'minors', Minor::class)
                ->fields(function() {
                    return [
                        Text::make(__('Relative'), 'relative')
                        ->displayUsing(function(){
                            return isset($this->pivot) ? $this->pivot->relative : '-';
                        }),

                        Boolean::make(__('is_family_admin'), 'is_admin')
                               ->displayUsing(function(){
                                   return isset($this->pivot) ? $this->pivot->is_admin : 0;
                               })->exceptOnForms()->canSee(function($request){
                                return $request->user()->usertype->role === UsertypeEnum::PRINCIPAL;
                            }),

                        Boolean::make(__('is_family_admin'), 'is_admin')
                               ->displayUsing(function(){
                                   return isset($this->pivot) ? $this->pivot->is_admin : 0;
                               })->canSee(function($request){
                                return $request->user()->usertype->role === UsertypeEnum::ADMIN;
                            })
                    ];
                })->canSee(function($request){
                    return $this && $this->user && $this->user->usertype->role === UsertypeEnum::TUTOR;
                }),
        ];
    }

    /**
     * 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 [
            new Filters\IndividualInsitute
        ];
    }

    /**
     * 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 [];
    }
}

Zerion Mini Shell 1.0