0
我想做一個包含'to'和'from'參數的查詢。我試圖將'to'和'from'傳遞給控制器,以便在查詢中使用,但Input::get('to')
會爲我嘗試的所有內容返回NULL
的值。Laravel日期查詢不傳遞來自控制器的數據
查看:
From: <input id="from" name="from" type="text" class="form-control input-md">
To: <input id="to" name="to" type="text" class="form-control input-md"><br />
@foreach($company->users as $user)
{{ Form::open(array('route' => array('SearchCredit',
$user->id), 'role'=>'form')) }}
<tr>
<td><button type="submit" value="{{ $user->id }}"
class="btn btn-link">
{{ $user->firstname}} {{$user->surname }}</button></td>
<td>{{ $user->credits_sum->sum }}</td>
</tr>
{{ Form::close() }}
@endforeach
路線:
Route::post('agents/admin/account/{id}',
array('as' => 'SearchCredit',
'uses' => '[email protected]'));
控制器:
public function postSearchCredit($id)
{
$from = Input::get('to');
$to = Input::get('from');
$alerts = Alert::with('location')
->where('user_id', '=', $id)
->where('created_at', '>', $from)
->where('created_at', '<', $to)
->get();
$this->layout->content = View::make('agents.admin.search',
array('alerts' => $alerts));
}
}
我不想日期被重複多次,所以我不希望把它放在foreachloop
裏面。
任何幫助將非常感激。
我不想日期被多次重複做。 'Form :: open'和'Form :: close'在一個'foreachloop'內。 – Ben
@Svengali我編輯了答案 –
謝謝你的回覆。不幸的是,我試過這個,但是因爲它已經被取出了循環,所以找不到'user-> id'。 'Form :: open'使用foreachloop來填充'user_id'。 – Ben