PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 28, 2022

[FIXED] POST Method in route gives error 404 - Laravel

 January 28, 2022     laravel     No comments   

Issue

I want to generate a random password on button click but it leads to Error 404

The Form

<form style="position: relative; left: -15px" action="{{ route("dashboard.users.generate-app-password-store") }}" method="POST">                       
   @csrf

    <button type="submit" class="btn btn-primary float-right mt-2">
        {{ trans("translation.generate-password") }}
    </button>
</form>

The Controller Function

public function generateAppEmailPasswordStore(Request $request)
{
    $user = User::findOrFail($request->uid);

    $user->app_email_password_store = Hash::make(Str::random(8));
    
    $user->app_email_password_store = $request->app_email_password_store;
    
    $user->save();  
    
    Alert::flash(trans('translation.email-account-created'));

    return redirect()->route('dashboard.users.profile', ['id' => $user->id]);
}

The route (prefix => dashboard is the main route group)

Route::group(['prefix' => 'user', 'middleware' => 'checkRole:admin'], function () {
    Route::post('/generate-app-password-store', 'Dashboard\UsersController@generateAppEmailPasswordStore')->name('dashboard.users.generate-app-password-store');
});

The error enter image description here


Solution

You are probably recieving 404 because of this line in the controller method.

$user = User::findOrFail($request->uid)

Check if you get the correct value for $request->uid or if there is a user with the given ID.

Otherwise it will throw a 404 error.



Answered By - maazin
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing