【发布时间】:2018-02-22 06:30:11
【问题描述】:
我正在尝试通过从数据库记录和存储中删除单个用户 cmets 和与它们相关的图片来删除它们。不幸的是,我不断收到错误。以下是我到目前为止的代码。
表: 评论:id、评论、user_id、person_id 图片:id、图片、comment_id、user_id、person_id
关系: 评论:
public function pictures()
{
return $this->hasMany('App\Picture', 'comments_id', 'id');
}
图片:
public function comments()
{
return $this->belongsTo('App\Comment', 'comments_id');
}
控制器:
public function destroy($id)
{
$comment = Comment::find($id);
Storage::delete($comment->pictures());
$comment->delete();
Session::flash('success', 'Your comment and pictures were deleted');
return redirect()->route('home');
}
有什么想法吗?
【问题讨论】:
-
错误是什么??
-
它不会同时删除评论和相关图片。
标签: php laravel laravel-5 eloquent laravel-5.5