Laravel Controller Return View
The typical way of returning the view form controller method in Laravel look as follows.
<?php // PostController.php public function show() { return view('posts.show', ['post' => Post::first()]); }
Laravel Controller Render View Beforehand
To render the view beforehand you can call the "render()" method available from the "view()" helper method. By calling the render method you will instruct Laravel to render the code beforehand and you can store it as a variable.
<?php // PostController.php public function show() { $partialView = view('partial.some-view', ['post' => Post::first()])->render(); // do whatever you want with the code return view('posts.show', ['post' => Post::first(), 'partialView' => $partialView]); }
Leave a reply