laravel-role icon indicating copy to clipboard operation
laravel-role copied to clipboard

Refactor Requests from separate Request file For entire project - [Anyone could take this and give a PR]

Open ManiruzzamanAkash opened this issue 1 year ago • 0 comments

In this codebase, we've made validation inside of the controller's method. We should move it to separate Requests folder and manage the request validation from that file.

Example -

php artisan make:request StoreAdminRequest
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'name' => 'required|max:50',
            'email' => 'required|max:100|email|unique:admins',
            'username' => 'required|max:100|unique:admins',
            'password' => 'required|min:6|confirmed',
        ];
    }
}

ManiruzzamanAkash avatar Jul 04 '24 19:07 ManiruzzamanAkash