shan_biswas's avatar

From Request Validation - HttpException - This action is unauthorized

I am a newbie in laravel. I am following "https://laravel.com/docs/5.4/validation#form-request-validation" to validate my form. So I created a Form Request named "ValidateRegistration" using "php artisan make:request ValidateRegistration" command. After I run this command a new file created under "app\Http\Controllers\Request" directory.

I have place "use App\Http\Requests\ValidateRegistration;" in my user controller file "UserController.php" and modified the "store()" function from "public function store(Request $request){}" to "public function store(ValidateRegistration $request){}"

But when I submit the form I got an error "HttpException. This action is unauthorized. in Handler.php(line 133)"

0 likes
2 replies
XavRsl's avatar
XavRsl
Best Answer
Level 11

In your ValidateRegistration object, you need to set the authorize() method to return true.

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

You'll have to do that every time you create a formRequest object. This method allows you to set the authorizations for the request.

6 likes
shan_biswas's avatar

Oh thank you so much. Finally solved it after fighting for 3 days. Thanks a lot.

1 like

Please or to participate in this conversation.