create loading and handle from js create edit and delete roles
This commit is contained in:
@@ -35,18 +35,18 @@ class RolesController extends Controller
|
||||
{
|
||||
try{
|
||||
$request->validate([
|
||||
"name" => "required",
|
||||
"name" => "required|unique:roles,name",
|
||||
"description" => "nullable",
|
||||
]);
|
||||
|
||||
DB::beginTransaction();
|
||||
Role::create($request->all());
|
||||
DB::commit();
|
||||
return redirect()->route("roles.index")->with('success','Succesfully Created');
|
||||
return response()->json(['message' => 'Role created successfully'], 201);
|
||||
}
|
||||
catch(\Exception $e){
|
||||
DB::rollBack();
|
||||
return redirect()->back()->with("error", $e->getMessage());
|
||||
return response()->json(['message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,10 +83,10 @@ class RolesController extends Controller
|
||||
DB::beginTransaction();
|
||||
$role->update($validatedData);
|
||||
DB::commit();
|
||||
return redirect()->route('roles.index')->with('success','Successfully updated');
|
||||
return response()->json(['message' => 'Role updated successfully'], 200);
|
||||
}catch(\Exception $e){
|
||||
DB::rollBack();
|
||||
return redirect()->back()->with("error", $e->getMessage());
|
||||
return response()->json(['message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,11 +97,13 @@ class RolesController extends Controller
|
||||
{
|
||||
try{
|
||||
DB::beginTransaction();
|
||||
Role::findOrFail($id)->delete();
|
||||
$deleted = Role::findOrFail($id)->delete();
|
||||
info("deleted". $deleted);
|
||||
DB::commit();
|
||||
return response()->json(array('success' => true, "message" => "Successfully deleted"));
|
||||
}catch(\Exception $e){
|
||||
DB::rollBack();
|
||||
return redirect()->back()->with("error", $e->getMessage());
|
||||
return response()->json(array('success' => false, "message" => $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
25
app/View/Components/ModalConfirmation.php
Normal file
25
app/View/Components/ModalConfirmation.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class ModalConfirmation extends Component
|
||||
{
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*/
|
||||
public function render(): View|Closure|string
|
||||
{
|
||||
return view('components.modal-confirmation');
|
||||
}
|
||||
}
|
||||
25
app/View/Components/ToastNotification.php
Normal file
25
app/View/Components/ToastNotification.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class ToastNotification extends Component
|
||||
{
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*/
|
||||
public function render(): View|Closure|string
|
||||
{
|
||||
return view('components.toast-notification');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user