0
votes

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

2
That's not enough information to make sense of where your problem might be. What's $create? What's your controller action look like? Do you have views in the root of your project? - fubar
what does $create->var_name? - AddWeb Solution Pvt Ltd

2 Answers

0
votes

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

}
0
votes

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.