user roles, bug fixes
This commit is contained in:
@@ -16,7 +16,6 @@ use Illuminate\Support\Str;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
|
||||
|
||||
|
||||
class ClientsController extends Controller
|
||||
{
|
||||
public function index(){
|
||||
@@ -890,7 +889,7 @@ class ClientsController extends Controller
|
||||
'invoice_amount' => 'required|numeric',
|
||||
'invoice_date' => 'required|date',
|
||||
'invoice_status' => 'required|string',
|
||||
'remarks' => 'sometimes|string'
|
||||
'remarks' => 'nullable|string'
|
||||
]);
|
||||
|
||||
// Find the record and update it
|
||||
|
||||
@@ -118,8 +118,12 @@ class NetworkOperatorsController extends Controller
|
||||
public function show($id)
|
||||
{
|
||||
$operator = NetworkOperator::findOrFail($id);
|
||||
|
||||
// Fetch all services for the dropdown
|
||||
$allServices = \App\Models\Service::orderBy('name')->get();
|
||||
|
||||
$staffMembers = \App\Models\StaffMember::orderBy('name')->get();
|
||||
return view('network_operators.show', compact('operator', 'staffMembers'));
|
||||
return view('network_operators.show', compact('operator', 'staffMembers', 'allServices'));
|
||||
}
|
||||
|
||||
public function storeConnection(Request $request, $operatorId)
|
||||
@@ -169,6 +173,42 @@ class NetworkOperatorsController extends Controller
|
||||
'connection' => $connection
|
||||
]);
|
||||
}
|
||||
public function storeNote(Request $request, $operatorId)
|
||||
{
|
||||
$request->validate([
|
||||
'notes_body' => 'required|string',
|
||||
'services' => 'nullable|string|max:200'
|
||||
]);
|
||||
|
||||
$serviceName = null;
|
||||
if ($request->filled('services')) {
|
||||
// This will find the service if it exists, or create a new one in the database if the user typed a new tag
|
||||
$service = \App\Models\Service::firstOrCreate([
|
||||
'name' => trim($request->services)
|
||||
]);
|
||||
$serviceName = $service->name;
|
||||
}
|
||||
|
||||
\App\Models\MnoNote::create([
|
||||
'mno_id' => $operatorId,
|
||||
'services' => $request->services ?? '',
|
||||
'user_id' => auth()->id(), // Automatically assign the logged-in user
|
||||
'notes_body' => $request->notes_body,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Note added successfully!'
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroyNote($id)
|
||||
{
|
||||
$note = \App\Models\MnoNote::findOrFail($id);
|
||||
$note->delete();
|
||||
|
||||
return redirect()->back()->with('success', 'Note deleted successfully.');
|
||||
}
|
||||
|
||||
public function destroyConnection($id)
|
||||
{
|
||||
|
||||
@@ -45,11 +45,16 @@ class StaffMembersController extends Controller
|
||||
|
||||
// dd($staffMembers);
|
||||
// dd(\Auth::user()->designation);
|
||||
|
||||
$systemRoles = \App\Models\ErpSystemRole::orderBy('name')->get();
|
||||
|
||||
|
||||
$data = [
|
||||
'staffMembers' => $staffMembers,
|
||||
'departments' => $departments,
|
||||
'allstaffMembers' => $allstaffMembers,
|
||||
'countries' => $countries,
|
||||
'systemRoles' => $systemRoles
|
||||
];
|
||||
|
||||
|
||||
@@ -73,12 +78,17 @@ class StaffMembersController extends Controller
|
||||
$validated['profile_pic'] = $request->file('photo')->store('staff_profiles', 'public');
|
||||
}
|
||||
|
||||
// $user->roles()->syncWithoutDetaching([$roleId]); // Add without removing existing roles
|
||||
// $user->roles()->sync($roleIds); // Replace the user's role set
|
||||
|
||||
$validated['created_by'] = auth()->id() ?? 1;
|
||||
$validated['password'] = Hash::make('default_password');
|
||||
$validated['hire_date'] = now();
|
||||
|
||||
StaffMember::create($validated);
|
||||
|
||||
if ($request->has('roles')) {
|
||||
$staff->roles()->sync($request->roles);
|
||||
}
|
||||
return response()->json(['success' => true, 'message' => 'Staff member added successfully!']);
|
||||
}
|
||||
|
||||
@@ -107,6 +117,8 @@ class StaffMembersController extends Controller
|
||||
$validated['modified_by'] = auth()->id() ?? 1;
|
||||
|
||||
$staff->update($validated);
|
||||
$staff->roles()->sync($request->roles ?? []);
|
||||
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Staff member updated successfully!']);
|
||||
}
|
||||
@@ -152,7 +164,7 @@ class StaffMembersController extends Controller
|
||||
}
|
||||
public function showDetails($id)
|
||||
{
|
||||
$staff = StaffMember::with('dependents')->findOrFail($id);
|
||||
$staff = StaffMember::with(['dependents', 'roles'])->findOrFail($id);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
|
||||
28
app/Http/Middleware/CheckRole.php
Normal file
28
app/Http/Middleware/CheckRole.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CheckRole
|
||||
{
|
||||
public function handle(Request $request, Closure $next, ...$roles)
|
||||
{
|
||||
// Check if the user is logged in
|
||||
if (!auth()->check()) {
|
||||
return redirect('login');
|
||||
}
|
||||
|
||||
$user = auth()->user(); // Assuming StaffMember acts as your Authenticatable user
|
||||
|
||||
// Check if the user has any of the allowed roles
|
||||
foreach ($roles as $role) {
|
||||
if ($user->hasRole($role)) {
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user