Send post data from controller to view

Created 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'));

Related Queries

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.