Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 1319 | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

    namespace App\Http\Requests;

    use App\Models\BackendUser;
    use Illuminate\Foundation\Http\FormRequest;
    use Illuminate\Validation\Rule;

    class UserUpdateRequest extends FormRequest
    {
        /**
         * Determine if the user is authorized to make this request.
         *
         * @return bool
         */
        public function authorize(): bool
        {
            if ( $_SESSION["admin"]["uid"] == $this->user()->id || $_SESSION["admin"]["user"]->admin == 1 || isset( $GLOBALS["user_rechte"]["admin"]["admin"] ) )
            {
                return true;
            }
            return false;
        }

        /**
         * Get the validation rules that apply to the request.
         *
         * @return array<string, mixed>
         */
        public function rules(): array
        {
            return [
                'email'             => 'bail|required|email|max:255', Rule::unique( BackendUser::class )->ignore( $this->user()->email ),
                'employee'          => 'integer|in:0,1',
                'rank'              => 'integer|min:0|max:500',
                'terminpflege'      => 'integer|in:0,1',
                'ignoreRemoteHosts' => 'integer|in:0,1',
                'description'       => 'sometimes',
                'phone'             => 'sometimes',
                'fax'               => 'sometimes',
                'save_session'      => 'integer|in:0,1',
                'app_user'          => 'integer|in:0,1',
            ];
        }

        protected function prepareForValidation(): void
        {
            $this->merge( [ "email" => $this->user . "@" . env( "shop" ) ] );
        }
    }