2017-09-06 18 views
0

我想知道是否有任何方法或方法將查詢發佈到不同的控制器(或函數),即2個或更多的laravel形式。我使用的是Laravel 5.4,我想從多個表中提取數據(在我的情況下是3),然後將視圖返回到頁面上的不同頁面或不同的藥片/標籤。如何將查詢發佈到Laravel 5.4中的不同控制器?

我的控制器看起來像:

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

我的路線是這樣的:

Route::post('/query', '[email protected]'); 

Route::post('/search', '[email protected]'); 

我的形式如:

{!! Form::open(['url' => 'search']) !!} 

請建議我一些方法。在此先感謝

+0

您是否想每次處理所有設定路線的發佈請求?或一次只有一個? –

+0

如果有效,我可以進行必要的更改。 –

+0

檢查此鏈接 - https://stackoverflow.com/questions/10955097/how-can-i-post-to-multiple-urls-at-the-same-time –

回答

0

如果我理解正確的:

路線:

Route::post('/search', '[email protected]'); 

控制器:

class QueriesController extends Controller 
{ 
    public function handlSearch(Request $request) { 
     $tabs = []; 

     $tabs[] = $this->search($request); 
     $tabs[] = $this->query($requst); 

     return \View::make('path.to.your.view', [ 
      'tabs' => $tabs 
     ]) 
    } 


    protected function search(Request $search) 
    { 
     // Your stuff 

     return \View::make('path.to.tab.part', []) 
    } 

    protected function query(Request $query) 
    { 
     // Your stuff 

     return \View::make('path.to.tab.part', []) 
    } 

} 

我覺得沒有辦法來處理與一個以上的請求路線。如果你想這樣做,你應該用一條路線來捕捉請求。然後在控制器中,您可以調用其他處理程序方法。

+0

明白了你的觀點。使用這個處理程序,我可以同時拋出表數據? –

+0

你的意思是用處理程序返回的視圖填充jQuery選項卡/藥丸? –

+0

我正在使用Bootstrap選項卡/藥丸。在每個標籤/藥丸我想要捕獲返回數據。 –

相關問題