return view with data laravel code example
Example 1: laravel pass view with data
return view("blog", ["posts"=>$posts]);
Or:
return view("blog", compact("posts"));
Example 2: laravel load view in variable
$html = view('users.edit', compact('user'))->render();
Example 3: return view with variable laravel
return View::make('blog')->with('posts', $posts);
Example 4: passing data from controller to blade view laravel
public function index(Request $request)
{
....
return view('pages.eventPage', compact('id', 'event', 'n'));
}
Example 5: laravel routes return view in web.php
Route::get("/page", function(){
return View::make("dir.page");
});
Example 6: laravel pass variables to view
return view('home')->with('userName',$userName);