how to pass parameter to show() method in resource controller from another function

AL-zami

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);

}
martinczerwi

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Laravel - How to pass parameter from controller to route and use it in another controller?

From Dev

How to pass a function from another class as parameter?

From Dev

How to pass instance of Request from a controller function to another controller function

From Dev

How to remove show() function from resource controller in Laravel

From Dev

How to pass parameter to controller function

From Dev

How to pass parameter in another method?

From Dev

How to pass a const parameter from a member function into another member function?

From Dev

How to Pass parameter from AngularJS Directive to AngularJS controller function

From Dev

pass values from a function to another function in controller

From Dev

How to pass parameter from one async function to another in nodejs?

From Dev

pass function from parent controller to directive with parameter

From Java

How to pass function as parameter from java to kotlin method?

From Dev

how to pass parameter from POST method and do function call in flask?

From Dev

How to pass a non static method from a specific class as parameter to Function

From Dev

Laravel 9 how to pass parameter in url from one controller to another controller?

From Dev

How to pass a function as a parameter to another function?

From Dev

How to pass function as parameter to another function?

From Dev

How to pass a generic function as parameter to another function?

From Dev

How to pass inputs from one function to another using .apply method?

From Dev

NodeJS - How to pass url parameter to controller function?

From Dev

Pass parameter from one Powershell function to another

From Dev

How can I send the dropdown value on selection to pass as a parameter to another function within the same controller; angular

From Dev

Laravel How to pass post data from one post method to another post method within the same controller?

From Dev

How to pass values from method in model to another method, or controller in ruby on rails

From

How to pass parameter to FormType constructor from controller

From Dev

How to pass parameter from ActionLink to controller at runtime

From Dev

How to pass correctly parameter from view to controller?

From

Kotlin: how to pass a function as parameter to another?

From Javascript

How to pass a callback as a parameter into another function

Related Related

  1. 1

    Laravel - How to pass parameter from controller to route and use it in another controller?

  2. 2

    How to pass a function from another class as parameter?

  3. 3

    How to pass instance of Request from a controller function to another controller function

  4. 4

    How to remove show() function from resource controller in Laravel

  5. 5

    How to pass parameter to controller function

  6. 6

    How to pass parameter in another method?

  7. 7

    How to pass a const parameter from a member function into another member function?

  8. 8

    How to Pass parameter from AngularJS Directive to AngularJS controller function

  9. 9

    pass values from a function to another function in controller

  10. 10

    How to pass parameter from one async function to another in nodejs?

  11. 11

    pass function from parent controller to directive with parameter

  12. 12

    How to pass function as parameter from java to kotlin method?

  13. 13

    how to pass parameter from POST method and do function call in flask?

  14. 14

    How to pass a non static method from a specific class as parameter to Function

  15. 15

    Laravel 9 how to pass parameter in url from one controller to another controller?

  16. 16

    How to pass a function as a parameter to another function?

  17. 17

    How to pass function as parameter to another function?

  18. 18

    How to pass a generic function as parameter to another function?

  19. 19

    How to pass inputs from one function to another using .apply method?

  20. 20

    NodeJS - How to pass url parameter to controller function?

  21. 21

    Pass parameter from one Powershell function to another

  22. 22

    How can I send the dropdown value on selection to pass as a parameter to another function within the same controller; angular

  23. 23

    Laravel How to pass post data from one post method to another post method within the same controller?

  24. 24

    How to pass values from method in model to another method, or controller in ruby on rails

  25. 25

    How to pass parameter to FormType constructor from controller

  26. 26

    How to pass parameter from ActionLink to controller at runtime

  27. 27

    How to pass correctly parameter from view to controller?

  28. 28

    Kotlin: how to pass a function as parameter to another?

  29. 29

    How to pass a callback as a parameter into another function

HotTag

Archive