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");
}
CodePudding user response:
either change your dashboard.user.generate-app-password-store (instead of dashboard.users.generate-app-password-store) in your view
or
change your route prefix to users (instead of user)
CodePudding user response:
The problem seems to be that you mismatch the " usage.
action="{{ route("dashboard.users.generate-app-password-store") }}"
should be
action="{{ route('dashboard.users.generate-app-password-store') }}"
The reasoning is that you close the action too early.
action="{{ route("
CodePudding user response:
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.