I have this variable that should be in my url but includes the "." (dot). Sorry I am still noob in laravel.
Expected Result is localhost/myProject/public/var_name
Eror says
View [.sampleVariable] not found.
my line is
return view('/'.$create->var_name)->compact('anotherVar','anotherVar');
and my route isRoute::get('{var_name}', 'MyController@index');
Route is
Route::get('/{var_name}', 'MyController@index');
MyController
public function index($var_name)
{
return view('template.index', ['var_name' => $var_name])->compact('anotherVar','anotherVar');
}
Try below code. Your controller function code like:
public function index($var_name)
{
//Initiate your variable...
$anotherVar = '';
//Replace 'BLADEFILENAME' to you want to execute blade file name...
return view('BLADEFILENAME', compact('var_name','anotherVar'));
}
You can read more about php compact(). You can also pass variable value from controller to view by wrapping the variable in curly braces
Your route code like:
Route::get('/{var_name}', 'MyController@index');
Now you can use $var_name
& $anotherVar
into your blade file.