Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Route::get('/postcountry/{id}',function($id){

		$post_id = Post::where('id',$id)->get();

		$user_id= '';

		$country_id= '';

		foreach ($post_id as $post){
			$user_id =  $post->user_id;
		}
		 $country = User::where('id',$user_id)->get();
		foreach ($country as $value){
			$country_id =  $value->country_id;
		}
		$country =  Country::find($country_id);
		echo $country->country_name;
	});

i used this code in my App its work but its not professional way i think i have two oneToMany relation ship in my app first_one is CountryhasMany User and another one is User hasMany Post relation ship and in last , Country hasManyTrough relation with Post actually

I hope u understand

Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

belsen belsen Joined 30 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.