Learn how to write this statement using SQL in Laravel
P粉851401475
P粉851401475 2023-09-07 19:15:53
0
1
531

    select count('vehicules.id')
    from vehicules
      INNER JOIN (equipements, contenirs)
         ON (contenirs.vehicule_id = vehicules.id AND contenirs.equipement_id = equipements.id)
     WHERE(vehicules.KMActuel-contenirs.dernierKM > equipements.kilometrageMax);

This is the code I want to execute in Laravel. I tried the following code:

$special = DB::select("SELECT COUNT('vehicules.id') FROM vehicules INNER JOIN (equipements, contenirs) ON (contenirs.vehicule_id = vehicules.id AND contenirs.equipement_id = equipements.id) WHERE(vehicules.KMActuel-contenirs.dernierKM > equipements.kilometrageMax)");

I called a variable in the view and got the following error:

htmlspecialchars() expects parameter 1 to be string, array given (View: C:\laragon\www\GSMV\resources\views\dash.blade.php)

P粉851401475
P粉851401475

reply all(1)
P粉099145710

You cannot execute expressions in strings passed to regular Eloquent methods. You must use a primitive expression that can be parsed accordingly:

DB::table('vehicules')
    ->join('contenirs', 'vehicules.id', 'contenirs.vehicule_id') 
    ->join('equipements','equipements.id','contenirs.equipement_id') 
    ->whereRaw('vehicules.KMActuel-contenirs.dernierKM > equipements.kilometrageMax')
    ->select('vehicules.*', 'contenirs.designation')
    ->count('vehicules.id');
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!