Skip to content

Commit

Permalink
Merge pull request #52 from MariaInsyt/arthur
Browse files Browse the repository at this point in the history
Arthur
  • Loading branch information
kyagie committed Mar 19, 2024
2 parents a5fa651 + da17767 commit 07b783a
Show file tree
Hide file tree
Showing 4 changed files with 1,731 additions and 205 deletions.
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

0 comments on commit 07b783a

Please sign in to comment.