Cant acces my variable from Controller in View

- 1 answer

Ad

I am just started learning laravel and got stuck while practically doing and the issue is i cant retrieve the variable that i defined in my controller.php into one of my view let suppose (myview.blade.php).

I searched over web but cant get bold answer to solve.

Here is the code:

controller.php

class WelcomeController extends Controller {


    public function index()
    {
        return view('welcome');
    }

    public function about()
    {
        $name = 'Farrukh';
        return view('about')->with(name,'$name');
    }

}

myview.blade.php

<html>
<body>
<div>
    <h1>Hello {!! $name !!} !</h1>
</div>

</body>
</html>
Ad

Answer

Ad

Try passing like return view('about')->with('name',$name);

Ad
source: stackoverflow.com
Ad