routes.php
Route::post("/{user}/{char_name}", array(
'as' => 'char-profile-post',
'uses' => 'ProfileController@postDropDownList'));
Route::get("/{user}/{char_name}", array(
'as' => 'char-profile-get',
'uses' => 'ProfileController@getDropDownList'));
ProfileController.php
public function postDropDownList($user, $char_name) {
$user = Auth::user();
$char_name = Input::get('choose');
$char_name_obj = User::find($user->id)->characters()->where('char_name', '=', $char_name)->first();
return Redirect::route('char-profile-get', array(Session::get('theuser'), $char_name_obj->char_name));
}
public function getDropDownList($user, $char_name) {
return View::make('layout.profile')
->with('char_name', $char_name);
}
Snippet from layout.profile View
<form action="{{ URL::route('char-profile-post') }}" method="post">
<select name="choose">
<option value="choose">Choose a character</option>
@foreach($char_name as $c)
<option> {{ $c->char_name }} </option>
@endforeach
</select>
<input type="submit" value="Ok">
{{ Form::token() }}
</form>
ErrorException
Undefined variable: char_name
(View: C:\wamp\www\CaughtMiddle\tutorial\app\views\layout\profile.blade.php)
When writing the following I still receive this error.
<option> {{ $char_name['char_name'] }} </option>
My question is pretty obvious. Am I doing something wrong, or Laravel is truly incapable to send a couple of variables from the controller to the view?
Route::get("/{user}/{char_name}", array(. What do you pass in the URL? Did you posted your fullgetDropDownListfunction? What are you trying to accomplish?