For example, if you want to include the "comments" relationship to the "post" method, you can define it like below.
# app/Models/Post.php <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Post extends Model { protected $with = ['commenets'];
Otherwise, you can manually include the relation using the "load" method like below.
# app/Http/Controllers/PostController.php public function show(Post $post) { $postWithComments = $post->load('comments'); dd($postWithComments); }
Leave a reply