Home > Net >  Pass data from view to view and display in view laravel?
Pass data from view to view and display in view laravel?

Time:10-30

In Controller :

$data = [
  'name' => 'Jony',
  'age'. => 18
];
return View::make("user/detail", compact('data'));

In view/user/detail.blade.php

<!DOCTYPE html>
 <html lang="en-EN">
  <head>
    <meta charset="utf-8">
  </head>
  <body>
   <h1>Details</h1>
   <div class="user-informatio">
       //
       I want to display view : user.blade.php
       //
   </div>
  </body>
 </html>

In view/user/user.blade.php

<div>{{ $data['name'] }}</div> <br/>
<div>{{ $data['age'] }}</div>

I want to pass $data from detail.blade.php to user.blade.php and display user.blade form inside detail.blade. Please give me any ideas.Thanks

CodePudding user response:

You can @include user.blade.php file in it.

<div class="user-informatio">
   //
   I want to display view : user.blade.php
   //
   @include('user.user', $data)
</div>

CodePudding user response:

try this

return view('user/detail')->with('data', $data);

then in the view just use $data

  • Related