1

I have a big issue over here and I have no idea how to solve it.

routes.php:

Route::group(array('prefix' => 'user'), function() {

    Route::post('/{user}/{char_name}/selectedok', array(
        'as' => 'char-profile-post',
        'uses' => 'ProfileController@postDropDownList'
    ));   

    Route::get('/{user}/{char_name}/selectedok', array(
        'as' => 'char-profile-get',
        'uses' => 'ProfileController@getDropDownList'
    ));

});

ProfileController.php:

public function getDropDownList() {  

    return View::make('layout.profile');     

}



public function postDropDownList($user, $char_name) {

    if (Auth::check())
    {   
        $user = Auth::user();
        $selected_char = Input::get('choose');
        $char_name = User::find($user->id)->characters()->where('char_name', '=', $selected_char)->first();


        return Redirect::route('char-profile-get', array($user->username, $char_name->char_dynasty, $char_name->char_name))
                ->with('user', $user->username)
                ->with('charname', $char_name->char_name)
                ->with('dynastyname', $char_name->char_dynasty);



    }
}

Yes I know I redirect to char-profile-get with 3 parametres, but I only need 2. It doesn't bother me. As you observe, I redirect using ->with. The only way I will print the data in the view is by doing this in the view:

Your chosen character is

{{ Session::get('charname') }} {{ Session::get('dynastyname')}}

If I don't overwrite the variables in postDropDownList($user, $char_name) my URL will literally look like this:

 http://localhost/CaughtMiddle/tutorial/public/index.php/user/%7Buser%7D/%7Bchar_name%7D/selectedok

instead of this:

 http://localhost/CaughtMiddle/tutorial/public/index.php/user/SerbanSpire/Spirescu/selectedok?Serban

So the verdict. The parameters in the functions will never receive any data. I don't even know how to describe them, the functions' parameters are null, even if I redirect to the get route with the correct data. var_dump($user) or var_dump($char_name) doesn't print anything on the browser, dd($user) and dd($char_name) also doesn't print anything nor does print_r().

Is my solution a viable one? By redirecting using ->with and storing the data in Session? Because this solution will drive me into using Session::get() a lot, every time I use information from the database, but i don't update it! Stop me if I am wrong.

Why aren't the variable's from the route going to the parameters of my functions? If my functions wouldn't have any parameters, the code would work the same. Basically, those parameters are there for nothing.

1

3 Answers 3

1

I have finally managed to resolve my issue. I have made a new CharacterController.php file and I put the get function inside the new controller. This way the function's parameters will successfully arrive and be useful.

Sign up to request clarification or add additional context in comments.

Comments

0

You may try this

$user = Auth::user();
$char = $user->characters()->where('char_name', Input::get('choose'))->first();

return Redirect::route('char-profile-get')
               ->with('user', $user->username)
               ->with('charname', $char->char_name)
               ->with('dynastyname', $char->char_dynasty);

5 Comments

It does the same thing. The URL is done correctly, but the get route doesn't send any usable parametres to getDropDownList. var_dump($charname); doesn't do anything because this function's parametres' are basically null.
Actually, with just flashes data into session so make sure your session contains data by {{ dd(Session::all()) }} in the view.
Also your getDropDownList() doesn't accept any args, so don't pass any args.
I have tried that, but I will use Session::get() basically in the rest of my project. I don't think I will ever use normal variables again. Is this a viable solution?
Session::all() returns everything from session and I told you to check the session by dumping the session.
0

If i understand correct you just need

        return Redirect::route('char-profile-get', array(
        'username' => $user->username,
        'char_name' => $char_name->char_name))
        ->with('user', $user->username)
        ->with('charname', $char_name->char_name)
        ->with('dynastyname', $char_name->char_dynasty);

because you pass an empty array. now use Session::get('username') and Session::get('char_name') directly in the view (layout.profile)

2 Comments

public function getDropDownList($username, $char_name) { return View::make('layout.profile') ->with('char_name', $char_name); } the parametres are still empty in this function
You're wrong, learn laravel docs laravel.com/docs/responses. You get variable from air. You do not need the method's parameters and 'with' method on getDropDownList(). Variables that you pass with 'with' method may be retrieved with Session::get('passed_keyName') directly in the view untill you not refresh the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.