Page 模型新增關聯方法:
class Page extends Model {
public function comments() { return $this->hasMany(Comment::class, 'page_id', 'id'); }
}
Comment 模型設定 $fillable 允許批量賦值。
Route::post('comment/store', 'CommentsController@store');Comment::create(Input::all())Route::resource('comments', 'CommentsController');_method=DELETE 偽造表單自行建立 Article 模型、遷移、控制器、視圖,並加入與 Comment 的一對多關聯,完成前後台完整功能。