0

I think I might have discovered a bug. This is what I have until now.

Routes.php

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

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

CharacterController.php

class CharacterController extends BaseController{

    public function getDropDownList($user, $char_dynasty, $char_name) 
    {
        if(Auth::check()) 
        {
            $user = Auth::user();

            return View::make('layout.notification', array(
                        'user' => $user,
                        'char_dynasty' => $char_dynasty,
                        'char_name' => $char_name));
        }
        else 
        {
            return App::abort(404);
        }
    }

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

            return Redirect::route('char-profile-get', array(Session::get('theuser'), 
                                                            $char_name->char_dynasty, 
                                                            $char_name->char_name));
        }
    }
}

profile.blade.php (snippet)

<form action="{{ URL::route('char-profile-post') }}" method="post">
    <select name="choose">
        <option value="choose">Choose a character</option>
        <option> {{ $c_name }} </option>
    </select>
    <input type="submit" value="Ok">
    {{ Form::token() }}
</form>

The error says that $char_dynasty is undefined which is usually used

  <option> {{ $char_dynasty }} </option>

I changed to populate the drop down list with another variable to be able to execute the database query $char_name from postDropDownList.

If I do in function getDropDownList, var_dump($char_dynasty); var_dump($char_name) I get the following

     string 'Spirescu' (length=8)
     string 'Ion' (length=3)

The point is that the parameters in getDropDownList are with the correct data, but are not transfered to the View. What am I doing wrong? I don't know how to access the variables in the View?

I have also tried return View::make('layout.notification', compact('user' , 'char_dynasty' , 'char_name' ));

or

  $data = array(
            'user' => $user,
            'char_dynasty' => $char_dynasty,
            'char_name' => $char_name);

  return View::make('layout.notification', $data);

I receive the same error. or $data is not defined.

5
  • Isn't this a duplicate of your question yesterday: stackoverflow.com/questions/22027764/… Also, where are you calling profile.blade.php? It's not in your controller anywhere. Commented Feb 27, 2014 at 15:23
  • possible duplicate of Passing variables from route to controller Commented Feb 27, 2014 at 15:49
  • I have resolved my yesterday issue by making a new controller and putting the functions there. I did this because the parameters of my getDropDownList were empty. Now they are not. But something intriguing happened. As soon as I changed the View::make('layout.notification' to View::make('layout.profile' other variables used in layout.profile are now undefined. What should I do?$char_dynasty and $char_name now works, but the other variables are undefined which worked previosly. Commented Feb 27, 2014 at 15:59
  • i don't understand your problem. your question and your last comment contradicts each other. Commented Feb 27, 2014 at 17:54
  • If they now work, what did you do? How's the code looking now? What others variables? $c_name? How are you passing them? Commented Feb 28, 2014 at 0:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.