GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
File: /var/www/html/app/Http/Middleware/CheckIfSeller.php
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
use Symfony\Component\HttpFoundation\Response;

class CheckIfSeller
{
    public function handle(Request $request, Closure $next): Response
    {
        $user = Session::get('user');

        // Check if the user exists in the session
        if (!$user) {
            return redirect('/login')->with('status', 'Please log in to continue.');
        }

        // Verify phone status for the user
        $phoneStatus = DB::table('seller_nins')->where('user_id', $user['id'])->whereNull('phone_verified_at')->first();

        // Redirect if the user is not a seller or has a verified phone
        if ($user['role'] != 'seller') {
            return redirect('/nin-registration')->with('error', 'You are yet to verify your NIN and phone number');
        }
        if ($phoneStatus) {
            Session::put('user_phone', $user['phone']);
            return redirect('/verify-phone')->with('error', 'You are yet to verify your phone number');
        }

       

        return $next($request);
    }

}