New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to deal with joined tables #149
Comments
Hey, $property->region->name; If Why I wanted to clear the join difference - because I will drop every real JOIN support in next major release. The new fallback resolvers are much more worth for me but they prevent from using joins with the same result. |
@Gummibeer can example to load all posts have link to categories and subcategories on index with join or not join. Because have problem with join to display data and filter. |
Hey @minhvn , assumptions interface Post {
public function categories(): BelongsToMany;
} code // replace by any logic you want to retrieve the wanted categories
$categories = Category::take(3);
// this will retrieve all posts with a relation to any of the categories
$posts = Post::whereHas('categories', fn(Builder $q) => $q->whereKey($categories->pluck('id')->all()))->get();
// this will create a collection of all translated post titles
$posts->map->title; The examples uses PHP7.4 and collection higher order proxies. |
Excellent - just a hint for anyone else looking for this, when using get this does not work, will though with first or find. When you're using get() you get a collection. |
Hey, $posts->map->title; If you only need the first one the |
Hi bro, thank for that:
How to get All request with translate from category. |
To query if a model is translated in a given locale the package provides a Everything else is default Eloquent model and relationship handling. |
I have a regions table with a regions_translations - works fine
I have a properties table with a properties_translations - works fine
Where I am stuck at, and cannot find an example anywhere, is how to deal with the region_id in my properties table.
I hoped this would work
Property::withTranslation('region')->where("id", "=", $id)->get();
Unfortunately it does not, and only gets the property translations.
I have not got region name in my property
$translatedAttributes
And am joining regions with
public function region() { return $this->hasOne('App\Region', 'region_id', 'region_id'); }
Know doubt it is something simple, but it is driving me mad :)
The text was updated successfully, but these errors were encountered: