Jak zrobić zapytanie z dwóch tabel w Laravel Eloquent ?

0

Tabela: dict_groups

id name
1 pytania_latwe
2 pytania_trudne

Tabela: dicts
id | dict_groups_id | question
---------------- | -------------------
1 | 1 | pytanie 1 jest
2 | 1 | pytanie 2
3 | 2 | pytanie 8

Jak zrobić teraz takie zapytanie :

SELECT d.question 
FROM dicts d 
JOIN dict_groups dc ON dc.id = d.dict_groups_id
WHERE d.name = 'pytania_latwe'

tylko w laravel

$dc4 = Dict::with(['group' => function($query) {
    $query->where('name', 'pytania_latwe');
}])->get();

moja metoda GROUP w klasie DICT

 public function group() {
        return $this->hasOne('App\DictGroup', 'id', 'dict_group_id');
    }

ale to mi wyciaga wszystkie 3 wartosci zamiast tylko id 1 i id 2 z tabeli dicts
Jak to zrobic ?

1

A jak wygląda metoda w modelu Group? Bo relacje wypadałoby ustawić po obu stronach.

/edit

Dict.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Dict;
use App\DictGroup;

class Dict extends Model
{
    protected $fillable = ['dict_group_id', 'question'];

    public function group() {
        return $this->hasOne('App\DictGroup', 'id', 'dict_group_id');
    }
}

DictGroup.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Dict;
use App\DictGroup;

class DictGroup extends Model
{
    protected $fillable = ['name'];

    public function dicts() {
        return $this->hasMany('App\Dict', 'dict_group_id');
    }
}

przy schemacie tabeli dicts

        Schema::create('dicts', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('dict_group_id');
            $table->string('question');
            $table->timestamps();
        });

i dict_groups

        Schema::create('dict_groups', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->timestamps();
        });

Polecenie DictGroup::find(1)->dicts funkcjonuje prawidłowo ;)

1 użytkowników online, w tym zalogowanych: 0, gości: 1