-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
2,644 additions
and
1,939 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Auth; | ||
use Response; | ||
use App\User; | ||
use Illuminate\Http\Request; | ||
|
||
class NotificationController extends Controller | ||
{ | ||
|
||
public function get() | ||
{ | ||
$id = auth('api')->user()->getId(); | ||
$kelas = User::findOrFail($id); | ||
$notification = collect(); | ||
$unreadNotification = count($kelas->unreadNotifications); | ||
|
||
$i = 0; | ||
foreach ($kelas->notifications as $notif) { | ||
$username = User::where('id',$notif->data['user'])->select('name')->first(); | ||
|
||
$n = collect($notif); | ||
$n->put('user',$username); | ||
$notification->push($n); | ||
if (++$i == 15) break; | ||
} | ||
|
||
return response() | ||
->json([ | ||
'notification' => $notification, | ||
'unreadNotification' => $unreadNotification | ||
]); | ||
} | ||
|
||
public function getAll() | ||
{ | ||
$id = auth('api')->user()->getId(); | ||
$kelas = User::findOrFail($id); | ||
$notification = collect(); | ||
$unreadNotification = count($kelas->unreadNotifications); | ||
|
||
$i = 0; | ||
foreach ($kelas->notifications as $notif) { | ||
$username = User::where('id',$notif->data['user'])->select('name')->first(); | ||
|
||
$n = collect($notif); | ||
$n->put('user',$username); | ||
$notification->push($n); | ||
if (++$i == 50) break; | ||
} | ||
|
||
return response() | ||
->json([ | ||
'notification' => $notification, | ||
'unreadNotification' => $unreadNotification | ||
]); | ||
} | ||
|
||
public function markRead($id) | ||
{ | ||
auth('api')->user()->unreadNotifications->where('id', $id)->markAsRead(); | ||
|
||
return response() | ||
->json([ | ||
'marked' => true | ||
]); | ||
} | ||
|
||
public function markAllRead() | ||
{ | ||
$id = Auth::user('api')->getId(); | ||
|
||
$kelas = User::findOrFail($id); | ||
|
||
$kelas->unreadNotifications->markAsRead(); | ||
|
||
return response() | ||
->json([ | ||
'marked' => true | ||
]); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.