mercredi 2 mars 2016

Access user's properties (with pivot table) laravel 5.1

I have a users table. The user has possibility to upload a post. The post is saved well to the database. The users can follow each other - so on a pivot table each follower_id has followees_id.

I need to get the posts of the current user followee's . I am kinda messed with getting it from a pivot table.

Here's my code so far:

controller:

protected function get_followee_posts($followee_posts) ////$followee_posts passed from the route.
{
  $user = $this->user;
  $user->followee()->attach($followee_posts);
  $followee_posts = User::find($followee_posts);


}

view:

<div class="following_posts">

<p> Posts from people you're following: <p>


@foreach ($user->follower_id->followee_id->posts as $post)
<form action="/html/tags/html_form_tag_action.cfm" method="post">
<textarea name="comments" id="comments" style="width:96%;height:90px;background-color:white;color:black;border:none;padding:2%;font:22px/30px sans-serif;">
{!! $posts->full_post !!} </textarea>

</form>
@endforeach

route:

Route::get('hub/{followee_posts}','HubController@get_followee_posts')->name('followee_posts');

I am getting an error with the current code saying:

ErrorException in 7340f90cc5faf1a298fcc646b7248b22 line 105:
Trying to get property of non-object

Any help would be lovely. Thank you.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire