How do I get a assign a record value to a variable in Laravel 5.3? -


i need display vehicle records belonging properties of currenty logged on user. before pass data view need filter out properties except owned current user id.

i have relationship in vehicle model performs foreign key constraint.

public function propiedad(){     return $this->belongsto('app\property', 'propiedad_id','id' ); } 

my controller using filter before passing data view. assume have acquire property ids belong user before filter vehicles belong properties. having trouble.

    $user_properties = array(?????);     $vehiculo = vehiculo::where('propiedad_id', $user_properties); 

if properties table has user_id column on user model define vehicles hasmanythrough relationship like

public function vehicles() {     return $this->hasmanythrough(vehicle::class, property::class); } 

then in controller can do:

$users = user::with('vehicles')->get(); 

or single user

$vehicles= user::find($id)->vehicles; 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -