0
votes

I am trying to pass data to a laravel blade and get that displayed. Evidently I am missing something very basic. If I use laravel format {{ $test_message }}, it is not displaying the value. If I use <?php echo $test_message ; ?>. It is working. Code from my controller -

$data = ['message' => 'This is a test!'];
return view('test')->with([ 'test_message' => $data['message'] ]);    

View

    <html lang="en-US">
    <head>
        <meta charset="utf-8">
    </head>
    <body>
    <p> <?php echo  $test_message ; ?> </p>
    <p> {{ $test_message }}  </p>
    </body>
</html>

In the output, I have "This is a test! " for the php echo portion and {{$test_message}} for the next line.

3
What is your view file named? - James
test.php. I tried making changes to it and made sure that is indeed getting picked up. By the way, I am using php artisan serve command to test locally. Would that have any impact? - Jayadevan

3 Answers

5
votes

Your issue is that your view is missing the blade part of the extension and so Laravel is not running it through the blade compiler.

Rename it to test.blade.php.

0
votes
return view('test')->with('test_message', $data['message']);   

or

return view('test',['test_message' => $data['message']]); 
0
votes

try this

and your view name should be test.blade.php

return view('test',['test_message' => $data['message']]);