mercredi 16 mars 2016

Is it to Recommended to write Insert/Update/Delete Authorization code in same Request class?

I am writing the below code in Request Class for Validation and Authorization. So the Below code is for add/Update record.

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class UserRequest extends Request
{
    public function authorize()
    {
        if(\Auth::user()->isAdmin()) {
            return true;
        }
        return false;
    }

    public function rules()
    {
        return [
            'UserName' => 'required|max:50|min:3|unique:tbluser,UserName,' . 
                                                     \Request::get( 'UserID' ) . ',UserID',
        ];
    }
}

In case I have to put Authorization Validation for Delete User, Will I need to write another Request Class or I can do some manipulations in Existing Code?

I want to code Delete Authorization Validation in authorize() method.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire