I know that the route name for show($id)
method is some_name/parameter
.Here i have a login authentication mechanism and i want to show the user profile if the user passed the authentication.I have a function called loginUser()
inside my userController
.I want to redirect the user to user.show route on successful login.But i am not sure how to pass the parameter value to show method.Currently i am getting the error:
Missing required parameters for [Route: user.show] [URI: user/{user}].
loginUser() function:
public function loginUser(Request $request){
$data = $request->all();
$rules = array(
'name' => 'required',
'password'=>'required'
);
// Create a new validator instance.
$validator = Validator::make($data, $rules);
if($validator->fails()){
$errors=$validator->messages();
return redirect()->back()->withErrors($validator);
}else{
if(Auth::attempt(['name'=>$request['name'],'password'=>$request['password']])){
return redirect()->route('user.show')->with('name',$request['name']); // pass control to show() function
}else{
return redirect()->back()->with('data', 'wrong username or password');
}
}
}
show() method in userController:
public function show($user)
{
//
$info=userModel::where('id','=',$user)->get(array('name'));
return View::make('user.show')->with('name',$info);
}
Your route user.show
needs an id to determine which user to show. Like this:
redirect()->route('user.show', [$userId])->with(...);
If for example $userId is 1, this would resolve to the URI: user/1
If you want to show the user index, that's a different route.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments