xxxxxxxxxx
Getting values from different tables
xxxxxxxxxx
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
/**
* Get the comments for the blog post.
*/
public function comments()
{
return $this->hasMany(Comment::class);
}
}
xxxxxxxxxx
use App\Models\Post;
$comments = Post::find(1)->comments;
foreach ($comments as $comment) {
//
}