HasMany Deep RelationshipGet local href value from anchor (a) tagClass design for relationshipsHow to fetch specific columns from multiple tables in Laravel 5?Conversion from query builder to eloquent model with 3 tablesLaravel 5 Hasmanythrough inverse queryingLaravel eloquent relationship fetch records upto third level of relationshipFetch data from Laravel query builder with with elquent relationshipNesting hasMany() relationships in LaravelLaravel Eloquent ORM hasMany where other pivoted relationship existsLaravel & relationshipshasMany, belongsTo, belongsToMany parameters with custom names?
Get contents before a colon
How do I portray irrational anger in first person?
Cauterizing a wound with metal?
Fixing a blind bolt hole when the first 2-3 threads are ruined?
Where should I draw the line on follow up questions from previous employer
Why is there no Disney logo in MCU movies?
Why does the weaker C–H bond have a higher wavenumber than the C=O bond?
What is the purpose of Strength, Intelligence and Dexterity in Path of Exile?
Board Chinese train at a different station (on-route)
Is "survival" paracord with fire starter strand dangerous
Can a network vulnerability be exploited locally?
How do you say "half the time …, the other half …" in German?
Historical Daf Yomi calendar
Under GDPR, can I give permission once to allow everyone to store and process my data?
What does "-1" represent in the value range for unsigned int and signed int?
How can I fix cracks between the bathtub and the wall surround?
How can I reply to coworkers who accuse me of automating people out of work?
is "prohibition against," a double negative?
What is this "opened" cube called?
Coupling two 15 Amp circuit breaker for 20 Amp
Is there a word or phrase that means "use other people's wifi or Internet service without consent"?
How to investigate an unknown 1.5GB file named "sudo" in my Linux home directory?
Did the Apollo Guidance Computer really use 60% of the world's ICs in 1963?
Can a Sorcerer use the Careful Spell Metamagic option on spells with optional saving throws?
HasMany Deep Relationship
Get local href value from anchor (a) tagClass design for relationshipsHow to fetch specific columns from multiple tables in Laravel 5?Conversion from query builder to eloquent model with 3 tablesLaravel 5 Hasmanythrough inverse queryingLaravel eloquent relationship fetch records upto third level of relationshipFetch data from Laravel query builder with with elquent relationshipNesting hasMany() relationships in LaravelLaravel Eloquent ORM hasMany where other pivoted relationship existsLaravel & relationshipshasMany, belongsTo, belongsToMany parameters with custom names?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have 5 models with one pivot table Country
Province
City
Area
Tour
tour_location
. How to achieve below functionality?
$country->tours
$province->tours
$city->tours
$area->tours
Country.php HasMany Provinces
public function provinces()
return $this->hasMany('AppProvince', 'country_id', 'id');
Province.php HasMany Cities
public function cities()
return $this->hasMany('AppCity', 'province_id', 'id');
City.php HasMany Areas
public function areas()
return $this->hasMany('AppArea', 'city_id', 'id');
Area.php BelongsToMany Tours
public function tours()
return $this->belongsToMany('AppTour', 'tour_locations');
php laravel relationship
add a comment |
I have 5 models with one pivot table Country
Province
City
Area
Tour
tour_location
. How to achieve below functionality?
$country->tours
$province->tours
$city->tours
$area->tours
Country.php HasMany Provinces
public function provinces()
return $this->hasMany('AppProvince', 'country_id', 'id');
Province.php HasMany Cities
public function cities()
return $this->hasMany('AppCity', 'province_id', 'id');
City.php HasMany Areas
public function areas()
return $this->hasMany('AppArea', 'city_id', 'id');
Area.php BelongsToMany Tours
public function tours()
return $this->belongsToMany('AppTour', 'tour_locations');
php laravel relationship
You can ckeck this link stackoverflow.com/questions/15439853/…
– Manisha
Mar 28 at 12:51
add a comment |
I have 5 models with one pivot table Country
Province
City
Area
Tour
tour_location
. How to achieve below functionality?
$country->tours
$province->tours
$city->tours
$area->tours
Country.php HasMany Provinces
public function provinces()
return $this->hasMany('AppProvince', 'country_id', 'id');
Province.php HasMany Cities
public function cities()
return $this->hasMany('AppCity', 'province_id', 'id');
City.php HasMany Areas
public function areas()
return $this->hasMany('AppArea', 'city_id', 'id');
Area.php BelongsToMany Tours
public function tours()
return $this->belongsToMany('AppTour', 'tour_locations');
php laravel relationship
I have 5 models with one pivot table Country
Province
City
Area
Tour
tour_location
. How to achieve below functionality?
$country->tours
$province->tours
$city->tours
$area->tours
Country.php HasMany Provinces
public function provinces()
return $this->hasMany('AppProvince', 'country_id', 'id');
Province.php HasMany Cities
public function cities()
return $this->hasMany('AppCity', 'province_id', 'id');
City.php HasMany Areas
public function areas()
return $this->hasMany('AppArea', 'city_id', 'id');
Area.php BelongsToMany Tours
public function tours()
return $this->belongsToMany('AppTour', 'tour_locations');
php laravel relationship
php laravel relationship
edited Mar 27 at 22:25
Kenny Horna
5,9221 gold badge14 silver badges45 bronze badges
5,9221 gold badge14 silver badges45 bronze badges
asked Mar 27 at 22:18
FayFay
411 silver badge14 bronze badges
411 silver badge14 bronze badges
You can ckeck this link stackoverflow.com/questions/15439853/…
– Manisha
Mar 28 at 12:51
add a comment |
You can ckeck this link stackoverflow.com/questions/15439853/…
– Manisha
Mar 28 at 12:51
You can ckeck this link stackoverflow.com/questions/15439853/…
– Manisha
Mar 28 at 12:51
You can ckeck this link stackoverflow.com/questions/15439853/…
– Manisha
Mar 28 at 12:51
add a comment |
1 Answer
1
active
oldest
votes
The direct way is do it with join
s, another way is to make a custom relationship extending the hasManyThrough()
. The third option -imo- is to use the Eloquent-has-many-deep package.
Using this package, you could do this:
class Country extends Model
use StaudenmeirEloquentHasManyDeepHasRelationships;
public function tours()
return $this
->hasManyDeep('AppTour', ['AppProvince', 'AppCity', 'AppArea', 'area_tour']);
Then in your controller:
// ...
$country = Country::find(1);
$tours = $country->tours;
Disclaimer: I'm not involved in this package in any way. I'm just suggesting it because is the simplest way to achieve your desired behavior.
Well this make sense, thanks @HCK
– Fay
Mar 27 at 22:30
yes Area has pivot table, but anyhow i got the idea.
– Fay
Mar 27 at 22:34
@Fay I've updated the method with -I think- is the right way to set up your relationships. Give it a try and tell me if this worked.
– Kenny Horna
Mar 27 at 22:35
its working like a charm.
– Fay
Mar 27 at 22:59
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387333%2fhasmany-deep-relationship%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The direct way is do it with join
s, another way is to make a custom relationship extending the hasManyThrough()
. The third option -imo- is to use the Eloquent-has-many-deep package.
Using this package, you could do this:
class Country extends Model
use StaudenmeirEloquentHasManyDeepHasRelationships;
public function tours()
return $this
->hasManyDeep('AppTour', ['AppProvince', 'AppCity', 'AppArea', 'area_tour']);
Then in your controller:
// ...
$country = Country::find(1);
$tours = $country->tours;
Disclaimer: I'm not involved in this package in any way. I'm just suggesting it because is the simplest way to achieve your desired behavior.
Well this make sense, thanks @HCK
– Fay
Mar 27 at 22:30
yes Area has pivot table, but anyhow i got the idea.
– Fay
Mar 27 at 22:34
@Fay I've updated the method with -I think- is the right way to set up your relationships. Give it a try and tell me if this worked.
– Kenny Horna
Mar 27 at 22:35
its working like a charm.
– Fay
Mar 27 at 22:59
add a comment |
The direct way is do it with join
s, another way is to make a custom relationship extending the hasManyThrough()
. The third option -imo- is to use the Eloquent-has-many-deep package.
Using this package, you could do this:
class Country extends Model
use StaudenmeirEloquentHasManyDeepHasRelationships;
public function tours()
return $this
->hasManyDeep('AppTour', ['AppProvince', 'AppCity', 'AppArea', 'area_tour']);
Then in your controller:
// ...
$country = Country::find(1);
$tours = $country->tours;
Disclaimer: I'm not involved in this package in any way. I'm just suggesting it because is the simplest way to achieve your desired behavior.
Well this make sense, thanks @HCK
– Fay
Mar 27 at 22:30
yes Area has pivot table, but anyhow i got the idea.
– Fay
Mar 27 at 22:34
@Fay I've updated the method with -I think- is the right way to set up your relationships. Give it a try and tell me if this worked.
– Kenny Horna
Mar 27 at 22:35
its working like a charm.
– Fay
Mar 27 at 22:59
add a comment |
The direct way is do it with join
s, another way is to make a custom relationship extending the hasManyThrough()
. The third option -imo- is to use the Eloquent-has-many-deep package.
Using this package, you could do this:
class Country extends Model
use StaudenmeirEloquentHasManyDeepHasRelationships;
public function tours()
return $this
->hasManyDeep('AppTour', ['AppProvince', 'AppCity', 'AppArea', 'area_tour']);
Then in your controller:
// ...
$country = Country::find(1);
$tours = $country->tours;
Disclaimer: I'm not involved in this package in any way. I'm just suggesting it because is the simplest way to achieve your desired behavior.
The direct way is do it with join
s, another way is to make a custom relationship extending the hasManyThrough()
. The third option -imo- is to use the Eloquent-has-many-deep package.
Using this package, you could do this:
class Country extends Model
use StaudenmeirEloquentHasManyDeepHasRelationships;
public function tours()
return $this
->hasManyDeep('AppTour', ['AppProvince', 'AppCity', 'AppArea', 'area_tour']);
Then in your controller:
// ...
$country = Country::find(1);
$tours = $country->tours;
Disclaimer: I'm not involved in this package in any way. I'm just suggesting it because is the simplest way to achieve your desired behavior.
edited Mar 27 at 22:34
answered Mar 27 at 22:25
Kenny HornaKenny Horna
5,9221 gold badge14 silver badges45 bronze badges
5,9221 gold badge14 silver badges45 bronze badges
Well this make sense, thanks @HCK
– Fay
Mar 27 at 22:30
yes Area has pivot table, but anyhow i got the idea.
– Fay
Mar 27 at 22:34
@Fay I've updated the method with -I think- is the right way to set up your relationships. Give it a try and tell me if this worked.
– Kenny Horna
Mar 27 at 22:35
its working like a charm.
– Fay
Mar 27 at 22:59
add a comment |
Well this make sense, thanks @HCK
– Fay
Mar 27 at 22:30
yes Area has pivot table, but anyhow i got the idea.
– Fay
Mar 27 at 22:34
@Fay I've updated the method with -I think- is the right way to set up your relationships. Give it a try and tell me if this worked.
– Kenny Horna
Mar 27 at 22:35
its working like a charm.
– Fay
Mar 27 at 22:59
Well this make sense, thanks @HCK
– Fay
Mar 27 at 22:30
Well this make sense, thanks @HCK
– Fay
Mar 27 at 22:30
yes Area has pivot table, but anyhow i got the idea.
– Fay
Mar 27 at 22:34
yes Area has pivot table, but anyhow i got the idea.
– Fay
Mar 27 at 22:34
@Fay I've updated the method with -I think- is the right way to set up your relationships. Give it a try and tell me if this worked.
– Kenny Horna
Mar 27 at 22:35
@Fay I've updated the method with -I think- is the right way to set up your relationships. Give it a try and tell me if this worked.
– Kenny Horna
Mar 27 at 22:35
its working like a charm.
– Fay
Mar 27 at 22:59
its working like a charm.
– Fay
Mar 27 at 22:59
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387333%2fhasmany-deep-relationship%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You can ckeck this link stackoverflow.com/questions/15439853/…
– Manisha
Mar 28 at 12:51