laravel has many
public function comments()
{
return $this->hasMany(Comment::class);
}
laravel has many
public function comments()
{
return $this->hasMany(Comment::class);
}
laravel has many
<?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('App\Models\Comment');
}
}
laravel has many with ids
class Post extends Model
{
public function comments()
{
return $this->hasMany(Comment::class, 'foreign_key', 'local_key');
// local id is the main id Of post table such as : id
// foreign id is the post table which is inside comment table such as: post_id
//return $this->hasMany(Comment::class, 'post_id', 'id');
//return $this->hasMany(Comment::class, 'post_id');
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us