简体   繁体   English

laravel 错误 传递给 Illuminate\Database\Query\Builder::whereBetween() 的参数 2 必须是数组类型

[英]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.

相关问题 类型错误:传递给 Illuminate\\Database\\Eloquent\\Builder::create() 的参数 1 必须是数组类型,给定的对象,在 laravel 中调用 - Type error: Argument 1 passed to Illuminate\Database\Eloquent\Builder::create() must be of the type array, object given, called in laravel 传递给 Illuminate\Database\Eloquent\Builder::create() 的参数 1 必须是数组类型 - Argument 1 passed to Illuminate\Database\Eloquent\Builder::create() must be of the type array 传递给 Illuminate\\Database\\Query\\Builder::cleanBindings() 的参数 1 必须是数组类型,给定的字符串, - Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, string given, 传递给 Illuminate\\Database\\Query\\Builder::update() 的参数 1 必须是数组类型,给定的字符串,调用 - Argument 1 passed to Illuminate\Database\Query\Builder::update() must be of the type array, string given, called in Laravel与MongoDB:传递给Illuminate \\ Database \\ Query \\ Builder :: __ construct()的参数2必须是Illuminate \\ Database \\ Query \\ Grammars的实例 - Laravel with MongoDB: Argument 2 passed to Illuminate\Database\Query\Builder::__construct() must be an instance of Illuminate\Database\Query\Grammars 传递给Illuminate \\ Database \\ Grammar :: parameterize()的参数1必须为数组类型-Laravel - Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array - Laravel Illuminate\Database\Query\Builder::cleanBindings(): 参数 #1 ($bindings) 必须是数组类型 - Illuminate\Database\Query\Builder::cleanBindings(): Argument #1 ($bindings) must be of type array 类型错误:传递给 Illuminate\Database\Eloquent\Builder::create() 的参数 1 必须是数组类型,给定 null - Type error: Argument 1 passed to Illuminate\Database\Eloquent\Builder::create() must be of the type array, null given Laravel错误参数1传递给Illuminate \\ Database \\ Connection :: prepareBindings()必须是数组类型,给定字符串,在 - Laravel error Argument 1 passed to Illuminate\Database\Connection::prepareBindings() must be of the type array, string given, called in Laravel 工厂参数 1 传递给 Illuminate\Database\Grammar::parameterize() 必须是数组类型,给定字符串 - Laravel factory Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM