I wish to build a new website based on my old website. To do that i use Laravel 4 (I cannot use laravel 5 because of the limitations of my hosting).
I have a problem on a MYSQL query that I want to transform into a Laravel Eloquent query.
"SELECT * FROM tbl_sondage WHERE sondage_home='1' AND (sondage_v1+sondage_v2+sondage_v3+sondage_v4+sondage_v5+sondage_v6+sondage_v7+sondage_v8+sondage_v9+sondage_v10) >= 40 ORDER BY RAND()"
Have you an idea of how I can transform this MYSQL Query into Laravel Eloquent Query?
I add (calculate) the result all the fields to verify them with a value (> 40) but I do not succeed in making Eloquent Query with that.
Thank you for your help.
something like this might work,
Model::where('sondage_home',1)->->orderBy(DB::raw('RAND()'))
->get()->filter(function($item){
return (($item->sondage_v1 + $item->sondage_v2) >= 40);
});
you can also use whereRaw('sql statement').
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community