public function updateRoles($id, Request $request)
{
Laralum::permissionToAccess('laralum.blogs.access');
# Check if blog owner
Laralum::mustOwnBlog($id);
$blog = Laralum::blog('id', $id);
$roles = Laralum::roles();
# Change user's roles
foreach ($roles as $role) {
if ($request->input($role->id)) {
# The admin selected that role
# Check if the blog was already in that role
if ($this->checkRole($blog->id, $role->id)) {
# The blog is already in that role, so no change is made
} else {
# Add the blog to the selected role
$this->addRel($blog->id, $role->id);
}
} else {
# The admin did not select that role
# Check if the blog is in that role
if ($this->checkRole($blog->id, $role->id)) {
# The blog is that role, so as the admin did not select it, we need to delete the relationship
$this->deleteRel($blog->id, $role->id);
} else {
# The blog is not in that role and the admin did not select it
}
}
}
# Return Redirect
return redirect()->route('Laralum::blogs')->with('success', "The blog's roles has been updated");
}