i have articles table and comments table. article_id is foriegn key in comments table. i cant save the article_id in reply comments table and im i getting this error. how to solve it? CommentController:
public function store(Article $article)
{
$this->validate(request(),['body' => 'required|min:2']);
$article = Comment::create([
'body' => request('body'),
'article_id' => $article->id,
]);
return back();
}
views.blade:
{{ csrf_field() }}
Add Comment
Comment model:
class Comment extends Model
{
public $timestamps = TRUE;
protected $table = 'comments';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'body',
'article_id'
];
public function article()
{
return $this->belongsTo(Article::class);
}
}
Route:
Route::post('/post/{post}/comment', 'CommentController@store');
Where I'm missing. Thanks in Advance