php - how to pass multiple table data to view in laravel 5.2 -


i have 3 tables in database,

--user

--profile

--education

user model

 public function profiledetails() {         return $this->hasone('app\profiledetails'); }  public function educationhasone() {         return $this->hasone('app\education'); } 

profiledetails model

public function user() {         return $this->belongsto('app\user'); } 

education model

public function user() {         return $this->belongsto('app\user'); } 

i able store data.

i view table data in 1 single webpage use below code make happen.

  public function index()  {  $user = auth::user()->id;  $profile = array(      user::find($user)->profiledetails,      user::find($user)->educationhasone   );  return view('profile.index', ['profile' => $profile]); } 

when use dd($variablename), able see required field needed,

now, know how pass data view in single page.

you can pass array view, so:

return view('profile', ['profile' => $profile]); 

in view, can access $profile.

if need data each, it's recommend use view composers. nice documentation + examples can find here: https://laravel.com/docs/5.1/views#passing-data-to-views


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -