App\Http\Controllers\Laralum\BlogsController::destroy PHP Метод

destroy() публичный Метод

public destroy ( $id )
    public function destroy($id)
    {
        Laralum::permissionToAccess('laralum.blogs.access');
        # Check permissions
        Laralum::permissionToAccess('laralum.blogs.delete');
        # Check if blog owner
        Laralum::mustOwnBlog($id);
        # Find The Blog
        $blog = Laralum::blog('id', $id);
        if ($blog->user_id == Laralum::loggedInUser()->id or Laralum::loggedInUser()->su) {
            # The user who's trying to delete the post is able to do such because it's the owner or it's su
            # Delete posts
            foreach ($blog->posts as $post) {
                $post->delete();
            }
            # Delete blog
            $blog->delete();
            # Return a redirect
            return redirect()->route('Laralum::blogs')->with('success', "The blog has been deleted");
        } else {
            #The user is not allowed to delete the blog
            abort(403, trans('laralum.error_not_allowed'));
        }
    }