Send post data from controller to view

Updated at 06-Sep-2021, By samar

Send post data from controller to view

In this article, we will see how to solve "Send post data from controller to view".

You can send post data from controller to view using return view() method. Before sending data to view you have to get the data from the post model using Post::all() method.
  • Get all post from table using controller and return to view in laravel 8

    --PATH app\Http\Controllers\<YourController>.php
    //Import post model after the namespace in laravel controller
    use App\Models\Post;
    
    //Method inside controller’s class to get all post
    public function index(){
        $posts = Post::all();
        return view('home', compact('posts'));
    }
    

Back to code snippet queries related laravel