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

Sanathoi's avatar

How to post query to different controllers in Laravel 5.4?

I am new to Laravel and wondering if there is any method or ways to post the query to different controllers (or functions) i.e 2 or more from a laravel form. I am using Laravel 5.4 and I want to extract data from multiple tables(3 in my case), then return view to different pages or different pills/tab on a page.

My controller looks like:

class QueriesController extends Controller { public function search(Request $search){ $data = $search->data; $tables= DB::table('tablename')->where('column', "$data")->get(); return view('/page1', compact('tables')); } public function query(Request $query){ $tdata= $query->data; $tables= DB::table('tablename')->where('column', "$tdata")->get(); return view('/page2', compact('tables')); } } My route looks like:

Route::post('/query', 'QueriesController@search'); Route::post('/search', 'QueriesController@query');

My form be like: {!! Form::open(['url' => 'search']) !!}

Individually, its working fine. Please suggest me some ways. Thanks in advance

0 likes
0 replies

Please or to participate in this conversation.