Laravel - Controller Return view->width does not pass data to the view

Asked

Viewed 31 times

0

My view does not have the data sent by the user

Controller

$posts = Models::post()->with('user')
                       ->where('chatter_discussion_id', '=', $discussion->id)
                       ->orderBy('created_at', 'ASC')
                       ->paginate(10); 
return view('chatter::discussion', compact('discussion', 'posts', 'corretor'));

Model

class Post extends Model
{
    protected $table = 'chatter_post';
    public $timestamps = true;
    protected $fillable = ['chatter_discussion_id', 'user_id', 'body'];

    public function discussion()
    {
        return $this->belongsTo(Models::className(Discussion::class), 
                               'chatter_discussion_id');
    }

View

@foreach($posts as $post)
//post->user nao tem nada é null
  • Come on, bro: Models::className(Discussion::class)?

1 answer

0

Your controller is wrong follow the change and do a test please.

$posts = Post::with('user')
                   ->where('chatter_discussion_id', '=', $discussion->id)
                   ->orderBy('created_at', 'ASC')
                   ->paginate(10);

return view('chatter::discussion', compact('discussion', 'posts', 'corretor'));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.