Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent

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.

Last updated 3 years ago.
0

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').

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

visualight visualight Joined 30 Dec 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.