Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

To better understand what you need, can you post how you did it without elequent

0

Hi Bostjan, of course, I change a little the Database but this is the same:

With this I get 9 users with name, lastname and the photo from imagenes table (photo table actually) while column perfil in imagenes table is true

This code is from my old site in laravel 4 without use Eloquent there.

$query = DB::table('users as U');
$query->leftJoin('imagenes as I', 'I.id_fk', '=', 'U.id');

$query->select('U.id as id', 'U.nombre as nombre', 'U.apellido as apellido', 'I.nombre as imagen');

$query->where('U.verificado', 1);
$query->where('I.perfil', 1);

$query->where('I.id_fk', '=', DB::raw("(SELECT MIN(id) FROM imagenes WHERE U.id = imagenes.id_fk)"));

$query->take(9);

$modelos = $query->get();

So I want make the same but with eloquent, if this is possibly of course.

Regards!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.

© 2024 Laravel.io - All rights reserved.