Last active
March 28, 2025 07:36
-
-
Save yesenvidnath/a40c196c09862ff463bde8362b89cd2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example : within this code we allow only the Admins to send bulk mesages | |
public function sendBulkNotification(Request $request) | |
{ | |
// Get the authenticated user | |
$authenticatedUser = Auth::user(); | |
// Check if the authenticated user is an admin | |
$isAdmin = DB::table('admins') | |
->where('user_ID', $authenticatedUser->user_ID) | |
->exists(); | |
// If not an admin, deny access | |
if (!$isAdmin) { | |
return response()->json([ | |
'message' => 'Unauthorized. Only admins can update professional profiles.' | |
], 403); | |
} | |
/// | |
/// | |
/// Other Codes that needed to happen comes After the valdation of the user type | |
/// | |
/// | |
$request->validate([ | |
'type' => 'required|in:meeting,payment,general', | |
'message' => 'required|string|max:255', | |
'user_type' => 'nullable|in:Customer,Professional,Admin', | |
'start_user_ID' => 'nullable|integer', | |
'end_user_ID' => 'nullable|integer', | |
]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Laravel API Restriction Bsed on User Type of Auth Token | |
// import this at the head of the code file | |
use Illuminate\Support\Facades\Auth; | |
// Check if the authenticated user is an admin | |
$isAdmin = DB::table('admins') | |
->where('user_ID', $authenticatedUser->user_ID) | |
->exists(); | |
// If not an admin, deny access | |
if (!$isAdmin) { | |
return response()->json([ | |
'message' => 'Unauthorized. Only admins can update professional profiles.' | |
], 403); | |
} | |
// please refer the example bellow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment