HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-26-0-120 6.17.0-1009-aws #9~24.04.2-Ubuntu SMP Fri Mar 6 23:50:29 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/www/html/orbidirectory.com/app/Http/Controllers/ReportedUserController.php
<?php

namespace App\Http\Controllers;

use App\Models\ReportedUser;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Yajra\DataTables\Facades\DataTables;

class ReportedUserController extends Controller
{
    public function store(Request $request)
{
    $request->validate([
        'transporter_name' => 'required|string|max:255',
        'reason' => 'required|string|max:255',
        'reported_user_image' => 'required|file|mimes:jpg,jpeg,png,pdf,mp4,mov,avi|max:10240', // 10MB limit
    ]);

    // Create the reported user first
    $reportedUser = ReportedUser::create([
        'name' => $request->name,
        'email' => $request->email,
        'transporter_name' => $request->transporter_name,
        'reason' => $request->reason,
        'status' => ReportedUser::Pending,
    ]);

    if ($request->hasFile('reported_user_image')) {
        $file = $request->file('reported_user_image');

        if (!$file->isValid()) {
            return redirect()->back()->with('error', 'Invalid file upload.');
        }

        if ($reportedUser->hasMedia('reported_user_image')) {
            $reportedUser->clearMediaCollection('reported_user_image');
        }

        $reportedUser->addMedia($file)
            ->usingFileName(time() . '_' . $file->getClientOriginalName())
            ->toMediaCollection('reported_user_image');
    }

    return redirect()->back()->with('report_success', 'Your report was submitted.');
}
    // public function store(Request $request)
    // {
    //     $request->validate([
    //         'transporter_name' => 'required|string|max:255',
    //         'reason' => 'required|string|max:255',
    //         'reported_user_image' => 'nullable|file|mimes:jpg,jpeg,png,pdf,mp4,mov,avi|max:10240',
    //     ]);
    
    //     // Create the reported user first
    //     $reportedUser = ReportedUser::create([
    //         'name' => $request->name,
    //         'email' => $request->email,
    //         'transporter_name' => $request->transporter_name,
    //         'reason' => $request->reason,
    //         'status' => ReportedUser::Pending,
    //     ]);
    
    //     if ($request->hasFile('reported_user_image')) {
    //         $file = $request->file('reported_user_image');
        
    //         if (!$file->isValid()) {
    //             return redirect()->back()->with('error', 'Invalid file upload.');
    //         }
        
    //         if ($reportedUser->hasMedia('reported_user_image')) {
    //             $reportedUser->clearMediaCollection('reported_user_image');
    //         }
        
    //         $reportedUser->addMedia($file)
    //             ->usingFileName(time() . '_' . $file->getClientOriginalName())
    //             ->toMediaCollection('reported_user_image');
    //     }
    //     return redirect()->back()->with('report_success', 'Your report was submitted.');
    // }

    // Show all reported users
    public function index(Request $request)
    {
        if ($request->ajax()) {
            $data = ReportedUser::latest();

            return DataTables::of($data)
                    ->addIndexColumn()
                    ->addColumn('uploaded_file', function($row) {
                        if ($row->getFirstMedia('reported_user_image')) {
                            $fileUrl = $row->getFirstMediaUrl('reported_user_image');
                            $fileName = basename($fileUrl);
                            
                            return '<a href="'.$fileUrl.'" download="'.$fileName.'" class="btn btn-primary btn-sm">Download</a>';
                        } else {
                            return 'No File';
                        }
                    })
                    ->addColumn('status', function($row) {
                        // Mapping numeric status to labels with Bootstrap badge classes
                        $statusLabels = [
                            ReportedUser::Pending => '<span class="badge bg-warning">Pending</span>',
                            ReportedUser::Valid => '<span class="badge bg-success">Valid</span>',
                            ReportedUser::Invalid => '<span class="badge bg-danger">Invalid</span>',
                        ];
                        return $statusLabels[$row->status] ?? '<span class="badge bg-secondary">Unknown</span>';
                    })
                    ->addColumn('action', function ($row) {
                        $btn = '';
                    
                        // If status is pending, show both Valid and Invalid buttons
                        if ($row->status == ReportedUser::Pending) {
                            $btn .= '<a href="javascript:void(0)" class="change-status btn btn-success btn-sm" data-id="' . $row->id . '" data-status="valid">Valid</a> ';
                            $btn .= '<a href="javascript:void(0)" class="change-status btn btn-danger btn-sm" data-id="' . $row->id . '" data-status="invalid">Invalid</a>';
                        } 
                        // If status is valid, show Invalid button
                        else if ($row->status == ReportedUser::Valid) {
                            $btn .= '<a href="javascript:void(0)" class="change-status btn btn-danger btn-sm" data-id="' . $row->id . '" data-status="invalid">Invalid</a>';
                        } 
                        // If status is invalid, show Valid button
                        else if ($row->status == ReportedUser::Invalid) {
                            $btn .= '<a href="javascript:void(0)" class="change-status btn btn-success btn-sm" data-id="' . $row->id . '" data-status="valid">Valid</a>';
                        }
                    
                        return $btn;
                    })
                    ->rawColumns(['action','uploaded_file','status'])
                    ->make(true);
        }
          
        return view('admin.reported_users.index'); 
    }
    
    public function updateStatus(Request $request)
    {
        $reportedUser = ReportedUser::find($request->id);
        if ($reportedUser) {
            $reportedUser->status = ($request->status == 'valid') ? ReportedUser::Valid : ReportedUser::Invalid;
            $reportedUser->save();
    
            return response()->json(['success' => true, 'new_status' => $reportedUser->status]);
        }
        return response()->json(['success' => false]);
    }
    
}