FEATURE: add form for setting default permissions and fix few bugs
This commit is contained in:
@@ -3,39 +3,41 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Permissions\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Permissions extends Controller
|
||||
{
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* Display all permissions
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function update(Request $request, User $user)
|
||||
public function index()
|
||||
{
|
||||
$permissionIds = $request->get('permissions', []);
|
||||
$permissions = Permission::whereIn('string_id', array_keys($permissionIds))
|
||||
->get();
|
||||
$permissions = Permission::whereNull('parent_id')->get();
|
||||
|
||||
\DB::transaction(function () use ($user, $permissions) {
|
||||
// remove all permissions
|
||||
$user->permissions()
|
||||
->detach();
|
||||
return view('admin/permissions.index', compact('permissions'));
|
||||
}
|
||||
|
||||
foreach ($permissions as $permission) {
|
||||
$user->permissions()
|
||||
->attach($permission->id);
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Setup default permissions
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function setDefault(Request $request)
|
||||
{
|
||||
Permission::where('default', true)
|
||||
->update(['default' => false]);
|
||||
|
||||
$permissions = $request->permissions;
|
||||
|
||||
Permission::whereIn('string_id', array_keys($permissions))
|
||||
->update(['default' => true]);
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', trans('admin/permissions.successfullySet'));
|
||||
->with('success', trans('admin/permissions.defaultSuccessfullySet'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user