diff --git a/app/Http/Controllers/NotificationController.php b/app/Http/Controllers/NotificationController.php index 7bd130ac..05b59a46 100644 --- a/app/Http/Controllers/NotificationController.php +++ b/app/Http/Controllers/NotificationController.php @@ -3,8 +3,56 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use App\Notification; +use Illuminate\Support\Facades\DB; +use Auth; class NotificationController extends Controller { - // -} + public function index() + { + return Notification::all(); + } + + public function show(Notification $notification) + { + return $notification; + } + + public function store(Request $request) + { + $notification = Notification::create($request->all()); + + return response()->json($notification, 201); + } + + public function update(Request $request, Notification $notification) + { + $notification->update($request->all()); + + return response()->json($notification, 200); + } + + public function delete(Notification $notification) + { + $notification->delete(); + + return response()->json(null, 204); + } + + public function getUserMessage() + { + return response()->json([ + "message" =>Notification::Where("user_id",Auth::user()->id)->get(), + "unread_message" =>Notification::Where([ + ["user_id",Auth::user()->id], + ["is_read",0] + ])->get() + ],200); + } + + public function readNotification(){ + $affected = DB::table('notifications')->Where('user_id', Auth::user()->id)->update(array('is_read' => 1)); + return response()->json("Read all message", 200); + } +} \ No newline at end of file diff --git a/app/Notification.php b/app/Notification.php index 893ef182..c9acda64 100644 --- a/app/Notification.php +++ b/app/Notification.php @@ -6,5 +6,5 @@ use Illuminate\Database\Eloquent\Model; class Notification extends Model { - protected $fillable = ['detail','user_id']; + protected $fillable = ['detail','user_id','is_read']; } diff --git a/database/migrations/2018_07_21_102920_create_notification_table.php b/database/migrations/2018_07_21_102920_create_notification_table.php index fcf67b87..7e3be228 100644 --- a/database/migrations/2018_07_21_102920_create_notification_table.php +++ b/database/migrations/2018_07_21_102920_create_notification_table.php @@ -16,7 +16,9 @@ class CreateNotificationTable extends Migration Schema::create('notifications', function (Blueprint $table) { $table->increments('id'); $table->string('detail'); + $table->string('link'); $table->unsignedInteger('user_id'); + $table->boolean('is_read')->default(0); $table->timestamps(); $table->foreign('user_id') diff --git a/database/seeds/NotificationSeeder.php b/database/seeds/NotificationSeeder.php index 5e567bf6..ac238997 100644 --- a/database/seeds/NotificationSeeder.php +++ b/database/seeds/NotificationSeeder.php @@ -19,6 +19,7 @@ class NotificationSeeder extends Seeder DB::table('notifications')->insert([ 'detail' => 'This is an user seeder notification', 'user_id' => $user->id, + 'link' => 'http://www.google.com', 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), ]); @@ -26,6 +27,7 @@ class NotificationSeeder extends Seeder DB::table('notifications')->insert([ 'detail' => 'This is an admin seeder notification', 'user_id' => $admin->id, + 'link' => 'http://www.google.com', 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), ]); diff --git a/resources/assets/js/components/Navbar.vue b/resources/assets/js/components/Navbar.vue index ccbabb91..464580d7 100644 --- a/resources/assets/js/components/Navbar.vue +++ b/resources/assets/js/components/Navbar.vue @@ -12,30 +12,24 @@