Laravel deletes a record. The record can only be deleted by its owner. How should the `destroy()` method be added?
阿神
阿神 2017-05-16 16:49:51
0
1
409

For example, if an article is to be deleted, only the creator of this article can delete it. How should the following destroy() method be added?


public function destroy($id)
    {
        $user = \Auth::user();
        //...
        Article::destroy($id);
        //...
    }
阿神
阿神

闭关修行中......

reply all(1)
Ty80

Pseudo code:

if(Article::findByid($id)->getAuthorId()==$user->id){
    Article::destroy()
}else{
    throw new Exception("没有删除权限");
}

The relatively correct approach is,

1. Don’t let him have the opportunity to press the delete button (hidden on the interface)
2. Judge before deleting

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template