HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: /var/www/javago-portal-updates/app/Http/Controllers/Cafe/NotificationController.php
<?php

namespace App\Http\Controllers\Cafe;

use App\Http\Controllers\Controller;
use App\Models\Notification;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Http\Request;

class NotificationController extends Controller
{

    private $notificationModel;

    public function __construct()
    {
        $this->notificationModel = new Notification;
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $data = [];
        $data = $this->notificationModel::where('notification_type', 1)
        ->orderBy('is_read', 'ASC')
        ->orderBy('created_at', 'DESC')
        ->get();
        if (!empty($data)) {
            foreach ($data as $item) {
                $user = User::where('id', $item->sender_id)->first();
                $item->title = __('common.notification.title');
                $item->description = __('common.notification.description', ['user'=>$user->name]);
                $item->date = Carbon::createFromTimestamp($item->created_at)->format('d-m-Y | h:i A ');
            }
        }
        return view('cafe.notification.index')->with('data', $data);
    }

    public function read(Request $request)
    {
        $notification = $this->notificationModel::where('id', $request->id)->update([
            'is_read' => 1
        ]);
        if ($notification) {
            return response()->json(['success' => true]);
        } else {
            return response()->json(['success' => false, 'message' => 'Notification not found.']);
        }
    }

    public function delete(Request $request)
    {
        // $notification = $this->notificationModel::where('id', $request->id)->update([
        //     'deleted_at' => Carbon::now()->timestamp,
        //     'is_read' => 1
        // ]);
        $notification = $this->notificationModel::where('id', $request->id)->delete();
        if ($notification) {
            return response()->json(['success' => true]);
        } else {
            return response()->json(['success' => false, 'message' => 'Notification not found.']);
        }
    }


    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        // return $this->customerModuleService->show($id);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }

    public function data()
    {
        // return $this->customerModuleService->data();
    }
}