I have facing the issue for after login user page 404 error. Please check the below code and help me the issue solve.
web.php
Route::get('/login','UserAuthController@login');
Route::post('/login-user','UserAuthController@LoginUser')->name('login-user');
Route::get('user/myprofile','UserAuthController@UserDashboard');
//Route::get('user/myprofile','UserAuthController@UserProfile')->name('UserProfile');
UserAuthController
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Users;
use Hash;
use Session;
class UserAuthController extends Controller
{
public function login(Request $request)
{
return view('pages.login');
}
protected function LoginUser(Request $request)
{
$request->validate([
'username'=>'required',
'password'=>'required'
],[
'username.required'=>"The User Name is Required.",
'password.required'=>"The Password is Required."
]);
$user = Users::where('username', '=', $request->username)->where('status', '=', 1)->first();
if ($user){
if (Hash::check($request->password, $user->password)){
$request->session()->put('userId',$user->userid);
//return redirect('user.myprofile');
//return redirect()->route('user.myprofile');
//return redirect()->intended('user/myprofile');
return redirect('UserDashboard');
}else{
return back()->with('fail', 'Password not matches. Please try again!!');
}
}else{
return back()->with('fail', 'This Username is not registered.');
}
}
public function UserDashboard (){
return view('user.dashboard');
}
}
After Login Page http://127.0.0.1:8000/UserDashboard 404 NOT FOUND
CodePudding user response:
Hi Replace your code from
return redirect('UserDashboard');
to
return redirect('user/myprofile');
CodePudding user response:
You should redirect with name route like:
Route::get('user/myprofile','UserAuthController@UserDashboard')->name('user-profile');
In Controller:
return redirect()->route('user-profile');
Also, make sure user.dashboard view file exist.
