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);
//...
}
PHP中文网2017-05-16 16:51:51
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