【发布时间】:2020-12-05 16:56:36
【问题描述】:
我是 laravel 的新手,这是我的第一个应用程序,
我想显示用户插入的 2 个日期之间的所有操作,但我收到此错误(传递给 Illuminate\Database\Query\Builder::whereBetween() 的参数 2 必须是数组类型,给定 null,在 C 中调用:\用户\tgtv\桌面)
操作表(id、vehicule、date、personal_id)
好的,现在这是我的搜索刀片 php
<form method="post" action="{{ route('etatperso.store') }}" enctype="multipart/form-data" width="20" height="20">
@csrf
<div class="form-group">
<label class="col-md-4">Personnel :</label>
<div class="col-md-8">
<select name="personnel_id" id="personnel_id" class="form-control" >
<option value="">Select Personnel</option>
@foreach($personnels as $personnel)
<option value="{{ $personnel->id}}">{{ $personnel->nom }}</option>
@endforeach
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4">Date debut :</label>
<div class="col-md-8">
<input type="date_debut" name="date_fin" value="{{ old('date', date('Y-m-d')) }}" class="form-control input-lg" />
</div>
</div>
<div class="form-group">
<label class="col-md-4">Date fin</label>
<div class="col-md-8">
<input type="date_fin" name="date_fin" value="{{ old('date', date('Y-m-d')) }}" class="form-control input-lg" />
</div>
</div>
<br/>
<div class="form-group text-center">
<input type="submit" name="add" class="btn btn-primary input-lg" value="Ajouter Personnel" />
</div>
</form>
这是我在控制器中的功能搜索
public function store(Request $request)
{
$personnels = Personnel::all();
$personnel_id=$request->get('personnel_id');
$date_debut=$request->get('date_debut');
$date_fin=$request->get('date_fin');
$data =Operation::where('personnel_id','LIKE',$personnel_id)->whereBetween('date',$date_debut,$date_fin)->paginate(1000);
return view('etatperso.resultat', compact('data','personnels'));
}
最后这是我的 result.blade.php
<table class="table table-bordered table-striped">
<th width="10%">ID</th>
<th width="10%">Vehicule</th>
<th width="10%">Personnel</th>
<th width="10%">Creation</th>
<th width="10%">Description</th>
<th width="10%">Date</th>
<th width="10%">Etat</th>
<th width="10%">Prix total</th>
</tr>
@foreach($data as $row)
<tr>
<td>{{ $row->id}}</td>
<td>{{ $row->vehicule }}</td>
<td>{{ $row->personnel->nom}}</td>
<td> {{$row->creation}}</td>
<td>{{ $row->description }}</td>
<td>{{ $row->created_at}}</td>
@if($row->etat =="en cours")
<td style="background-color: red;">{{ $row->etat}}</td>
@elseif($row->etat =="paye")
<td style="background-color: green;">{{ $row->etat}}</td>
@endif
<td>{{ $row->prix_total}}</td>
@if($row->etat =="paye")
<td>
<a href="{{ route('details', $row->id) }}" style="display: none;" class="btn btn-success btn-sm">Ajouter articles nécessaire</a>
<br> </br>
<a href="{{ route('liste_utilisee', $row->id) }}" class="btn btn-warning btn-sm">Liste des Articles Utilisés</a></td>
@elseif ($row->etat =="en cours")
<td>
<a href="{{ route('details', $row->id) }}" class="btn btn-success btn-sm">Ajouter articles nécessaire</a>
<br> </br>
<a href="{{ route('action', $row->id) }}" class="btn btn-danger btn-sm">Ajouter action</a>
<br> </br>
<a href="{{ route('liste_utilisee', $row->id) }}" class="btn btn-warning btn-sm">Liste des Articles Utilisés</a></td>
</tr>
@endif
@endforeach
</table>
【问题讨论】:
-
你只需要像下面这样使用它 Operation::where('personnel_id','LIKE',$personnel_id)->whereBetween('date',[$date_debut,$date_fin])- >分页(1000);
-
错误消失了但是....它不显示任何东西......:(
-
然后确保数据库中的数据是否存在于两个日期之间,并确保日期的格式。
-
aa 当我在 $date_debut 中使用 dd 但它返回 null .... 但我收到了我认为的请求:/