2014-12-11 56 views
0

我正在嘗試檢查POST數據是否已發送到頁面。 Google的快速搜索沒有任何結果。檢查POST數據是否發送到頁面

if(postdataisSent) 
{ 
    //do this 
} 
else 
$items = Gamefarm::where('roost_hen', '=', 1)->paginate(6); 
return View::make('gamefarms/index',compact('items')); 

回答

3

您可以使用if (Input::has('parameter'))來查看某個參數在POST的存在,或者您也可以通過默認進入的功能,然後進行測試,如果它的存在。

$parameter = Input::get('parameter', false); 
if ($parameter) 
{ 
    // do something with the data 
} 
else 
{ 
    // it's not present in the POST 
} 

要檢查存在的任何數據都:

$data = Input::all(); 
if (count($data) > 0) 
{ 
    // there is data in the POST 
} 
else 
{ 
    // there is no data in the POST 
} 

注意 - 您可以從any HTTP verb (GET, POST etc) using the same Input::get('data')

+0

感謝您的回答,先生訪問數據,但我不尋找一個特定的輸入,我只是想檢查一個表單是否提交到頁面 – 2014-12-11 02:14:22

+0

@jakebalba - 有很多選項可供您使用!用一個想法更新我的答案。看看Laravel文檔,它們確實很好:http://laravel.com/docs/4.2/requests#basic-input – msturdy 2014-12-11 02:18:26