0

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 is
Route::get('{var_name}', 'MyController@index');

Ralph
  • 193
  • 1
  • 4
  • 12

2 Answers2

0

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');

}
Ilya Yaremchuk
  • 2,007
  • 2
  • 19
  • 36
0

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.

AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57