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.

Answers 1
  • 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'));
    }
    
    0
  • Back to code snippet queries related laravel

Related queries helps you to understand and may also used for implementation of current code snippet