RequestAdminNews.php 1.24 KB
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Arr;

class RequestAdminNews extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, mixed>
     */
    public function rules()
    {
        if (in_array($this->route()->getName(), ['admin.new_admin_update'])) {
            // получаем модель Pages через маршрут admin/editor-pages/edit/{page}
            $model = $this->route('new_admin_edit');
        } else {
            $unique = 'unique:news,slug';
            $Array1['slug'] = [
                'required',
                'max:255',
                $unique,
                'regex:~^[-_a-z0-9]+$~i',
            ];
        }

        $Array1 = [
        'title' => [
                'required',
                'string',
                'min:3',
                'max:255',
            ],
                    'text' => [
                'required',
                'min:255',
            ],
        ];
        return $Array1;
    }
}