Hyperion Hyperion - 1 year ago 175
PHP Question

LARAVEL 5 :: Language switch? Error: Use of undefined constant language - assumed 'language'

So I'm trying to make a bilingual website that can switch from english to portuguese and vice-verse through a single click.

I'm getting this error:

Use of undefined constant language - assumed 'language'

In a random view I use:

<form action="{{ URL::route(language-chooser) }}" method="post">
<select name="locale">
<option value="en">English</option>
<option value="pt">Portuguese</option>
<input type="submit" value="Choose">
{{ Form::token() }}
<p>{{ trans('homepage.home') }}</p>

The LanguageController:

class LanguageController extends BaseController {

public function chooser()
Session::set('locale', Input::get('locale'));
return Redirect::back();

The route:

Route::post('/language', array(
'before' => 'csrf',
'as' => 'language-chooser',
'uses' => 'LanguageController@chooser',

I'm getting that error and I can't figure why... Thanks.

Answer Source

Strings should be wrapped in quotes. "" or ''. And your route name is a string so:

<form action="{{ URL::route('language-chooser') }}" method="post">