[英]laravel err Argument 2 passed to Illuminate\Database\Query\Builder::whereBetween() must be of the type array
i am new in laravel this is my first app well,我是 laravel 的新手,这是我的第一个应用程序,
i want to display all operations between 2 dates insert by user but i got this error(Argument 2 passed to Illuminate\Database\Query\Builder::whereBetween() must be of the type array, null given, called in C:\Users\tgtv\Desktop)我想显示用户插入的 2 个日期之间的所有操作,但出现此错误(传递给 Illuminate\Database\Query\Builder::whereBetween() 的参数 2 必须是数组类型,null 给定,在 C:\Users 中调用\tgtv\桌面)
operation table (id, vehicule, date, personnel_id)操作表(id、vehicule、date、personal_id)
okay now this is my search blade php好的,现在这是我的搜索刀片 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>
and this is my function search in the controller这是我在 controller 中搜索的 function
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'));
}
and finnaly this is my result.blade.php最后这是我的结果.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>
Try this:尝试这个:
$data =Operation::where('personnel_id','LIKE',$personnel_id)->whereBetween('date',[$date_debut,$date_fin])->paginate(1000);
WhereBetween second parameter must be in array. WhereBetween 第二个参数必须在数组中。 In your code change this
在您的代码中更改此
$data =Operation::where('personnel_id','LIKE',$personnel_id)->whereBetween('date',$date_debut,$date_fin)->paginate(1000);
to至
$data =Operation::where('personnel_id','LIKE',$personnel_id)->whereBetween('date',[$date_debut,$date_fin])->paginate(1000);
UPDATE更新
also change this也改变这个
<input type="date_debut" name="date_fin" value="{{ old('date', date('Y-m-d')) }}" class="form-control input-lg" />
to至
<input type="date_debut" name="date_debut" value="{{ old('date', date('Y-m-d')) }}" class="form-control input-lg" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.