Как сделать связь многие ко многим?

Немного не пойму как реализовывается связь многие ко многим. Пытаюсь понять, только пока что не доконца понял почему у меня ошибка выскакивает
Property [executes] does not exist on this collection instance.

Вначале она выскакивала когда я не поставил with в запросе, сейчас уже не пойму зачем она выскакивает
Вот моя реализация
Таблицы
execute
id
last_name
name

direction
id
name

execute_direction
id
direction_id
execute_id
В контроллере
$directions = Direction::where('id', 33)->with('executes')->get();
        $execute = [];
        foreach ($directions->executes as $value){
            $execute[] = $value;
        }
        dd($execute);

В моделе
<?php

namespace Growth;

use Illuminate\Database\Eloquent\Model;

class Direction extends Model
{
    protected $table = 'direction';
    protected $fillable = ['id_user', 'name'];

    public function executes()
    {
        return $this->belongsToMany('Growth\Execute', 'execute_direction');
    }
}

В execute_direction
<?php

namespace Growth;

use Illuminate\Database\Eloquent\Model;

class Execute_direction extends Model
{
    protected $table = 'execute_direction';
    protected $fillable = ['direction_id', 'execute_id'];
    public $timestamps = false;

    public function execute()
    {
        return $this->hasOne('Growth\Execute');
    }
}

Сейчас я не пойму где искать решение проблемы
  • Вопрос задан
  • 212 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы