php - How to retrieve all data using relation like outer join? -


based on below question answers able retrieve data of particular table not 3 table data in single array . how retrieve data using relation?

i tried following ways

  1. this retrieve users data instead of particular user

    user::find(1)->with('posts')->get(); 
  2. this retrieve post detail not user table

    $data = user::findorfail(1)->posts()->get(); 

please me retrieve data of 3 tables in single user in single query.

will user id 1 posts.

$data = user::findorfail(1)->load('posts'); 

or

$data = user::with('posts')->findorfail(1); echo "username:" . $data->name; foreach($data->posts $post) {     echo $post->title;     echo "comments:";     foreach($post->comments $comment) {         echo $comment->value;     } } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -