<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

class UserPermissionsController extends Controller
{
    public function index()
    {
        $lists = Permission::orderBy('name', 'ASC')->get();
        return view('user.user-permissions', compact('lists'));
    }
    /**Function to add a New Role into the Database**/
    public function showAddNewPermission()
    {
        return view('user.add-user-permission');
    }

    /**A Function to Store the Freshly created Role**/
    public function storeAddNewPermission(Request $request)
    {
        $name = $request->input('name');
        $res = 'name exists';
        if(!Permission::where('name', $name)->exists()) {
            $permission = Permission::make(['name' => $name]);
            $permission->saveOrFail();

             $res = 'success';
        }
        return $res;
    }
}
