2014-01-06 5 views
0

Мой код:Laravel - Нелегальная смещение типа HasMany()

$user = User::where('uid', $user_id)->with('groups.sub_groups')->firstOrFail(); 
return $user; 

На моей модели пользователя:

return $this->hasMany('group'); 

На моей группе модели:

return $this->hasMany('sub_group'); 

Теперь трассировки стека дает me ошибка:

Illegal offset type 
Illuminate/Database/Eloquent/Relations/HasOneOrMany.php 

    $foreign = $this->getPlainForeignKey(); 

    // First we will create a dictionary of models keyed by the foreign key of the 
    // relationship as this will allow us to quickly access all of the related 
    // models without having to do nested looping which will be quite slow. 
    foreach ($results as $result) 
    { 
     $dictionary[$result->{$foreign}][] = $result; 
    } 

обновление

удаление .sub_group не возвращает ошибку.

// works 
$user = User::where('uid', $user_id)->with('groups')->firstOrFail(); 

ответ

0

Вы уверены, что это отношения?

Должно иметь hasMany и принадлежит вашей группе Модель

Смежные вопросы