Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

khubab's avatar

How to show data from controller to view

I have a view having three datatables. each table has its own type of data. so there are three quries for three tables. How can i create a single controller to fetch data with three queries and pass to view. Please comment any example, fetch data from db with three quries and pass to single view

0 likes
1 reply
bobbybouwmann's avatar
public function show()
{
    $users = User::all();
    $posts = Post::all();
    $categories = Category::all();

    return view('some.view', compact('users', 'posts', 'categories'));
}

You can find this in the documentation as well: https://laravel.com/docs/5.6

2 likes

Please or to participate in this conversation.