Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arthur #52

Merged
merged 3 commits into from Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 17 additions & 14 deletions app/Http/Controllers/AgentNotificationController.php
Expand Up @@ -3,13 +3,11 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\AgentNotification;
use App\Models\Agent;

class AgentNotificationController extends Controller
{
//

//
public function agentNotifications(Request $request)
{
$agent = Agent::find($request->user()->agent_id);
Expand All @@ -32,25 +30,30 @@ public function agentNotifications(Request $request)

public function markAsRead(Request $request)
{
$request->validate([
'ids' => 'required|array',
]);

$agent = Agent::find($request->user()->agent_id);

if ($agent) {
$agent->notifications()
->whereIn('id', $request->ids)
->update(['read_at' => now()]);
$input = $request->all();

if ($agent){
if (isset($input['id'])) {
$agent->notifications()
->where('id', $input['id'])
->update(['read_at' => now()]);
} else {
$agent->notifications()
->unread()
->update(['read_at' => now()]);
}

return response()->json([
'message' => 'Notifications marked as read'
'message' => 'Notifications marked as read',
'unread' => $agent->notifications()
->unread()
->count(),
]);
} else {
return response()->json([
'message' => 'Agent not found'
], 404);
}

}
}
3 changes: 2 additions & 1 deletion app/Models/AgentNotification.php
Expand Up @@ -12,7 +12,6 @@ class AgentNotification extends Model
{
use HasFactory, SoftDeletes;

//Set user_id on creating
public static function boot()
{
parent::boot();
Expand All @@ -21,6 +20,8 @@ public static function boot()
});
}

//Todo: Make prunable

protected $fillable = [
'agent_id',
'user_id',
Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -16,6 +16,7 @@
"filament/forms": "^3.2",
"filament/notifications": "^3.2",
"guzzlehttp/guzzle": "^7.8",
"laravel-notification-channels/fcm": "^4.3",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.3",
"laravel/tinker": "^2.8"
Expand Down