Answer the question
In order to leave comments, you need to log in
How to add condition for nested relation in laravel?
Hello, there are following models:
class Page extends Model {
protected $with = ['blocks'];
public function blocks() {
return $this->belongsToMany('App\Block');
}
}
class Block extends Model {
protected $with = ['fields'];
public function fields() {
return $this->hasMany('App\Fields');
}
}
class Field extends Model {
protected $with = ['data'];
public function data() {
return $this->hasOne('\App\Data');
}
}
public function get() {
$page_id = 1;
$data = Page::find($page_id);
}
Страница
- Блок 1
- Поле 1
- Тестовые данные
- Поле 2
- Еще данные
- Блок 2
- Поле 1
- Другие данные
public function data() {
return $this->hasOne('\App\Data')->where('page_id', '=', $page_id);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question