D
D
Dmitry Kuznetsov2017-10-11 13:51:14
Laravel
Dmitry Kuznetsov, 2017-10-11 13:51:14

How to write an Eloquent query correctly?

Something I can not understand at all how to make the correct Eloquent request. Tell me please.
There are 2 tables:
Users :

id_users
login_users
kingdom_game

Kingdom :
id_kingdom
title_kingdom
name_kingdom

Need to get all users whose "kingdom_game" is equal to 'id_kingdom'. But that's not all... To receive a request, we have "name_kingdom", through it we need to get just the same all users.
PS: Or is it better not to take a steam bath and make it easier to receive through id_kingdom? I just have this url:
Route::group(['prefix' => 'kingdom'], function(){
      ...
      Route::get('{kingdomName}/players', ['as' => 'Kingdom.players', 'uses' => '[email protected]']);
    });

kingdomName - text value
I just want something prettier...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gleb Starkov, 2017-10-11
@dima9595

Kingdom::select(users.id_users, users.login_users)
    ->leftJoin('users', 'kingdom.id_kingdom', '=', 'users.kingdom_game')
    ->where('name_kingdom', $nameKingdom)
    ->get();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question