Answer the question
In order to leave comments, you need to log in
Laravel - how to write a greedy Eloquent query?
Need a greedy Eloquent query through models.
The models are already there: Pagetype, Page, Service and Category, and the pagetype_service table is created for the links.
The models already have the corresponding links with other models. You can also make new connections if necessary.
pagetypes
id
ru_name
sef_name
pagetype_service
id
page_id
pagetype_id
service_id
pages
id
title
h1
...
services
id
category_id
sef_url
price
...
сategories
id
parent_id
sef_url
...
Answer the question
In order to leave comments, you need to log in
Thank you, I tried a bunch of options here, but I found a solution.
I got it like this:
$sefName = 'проверка';
$pages = Page::whereHas('pagetypes', function ($query) use ($sefName) {
$query->where('sef_name', $sefName);
})->with('services.category')->get();
$sefName = 'проверка';
$pages = Page::whereHas('service', function($query) use ($sefName) {
$query->whereHas('pageType', function($query) use ($sefName) {
$query->where('sef_name', $sefName);
})->with('pageType');
})->with('service')->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question