<?php namespace App; use Illuminate\Http\Request; class Post extends Model { /** * These fields are OK for mass assignement. * * @var array */ protected $fillable = ['body', 'title']; /** * @param string $body */ public function addComment(string $body) { // Comment::create([ // 'body' => $body, // 'post_id' => $this->id, // ]); $this->comments()->create(compact('body')); } public function comments() { return $this->hasMany(Comment::class); } }