<?php

namespace App\Api\V1\Controllers;

use Symfony\Component\HttpKernel\Exception\HttpException;
use Tymon\JWTAuth\JWTAuth;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\User;
use App\Models\Driver;
use App\Models\Kid;
use App\Models\Route;
use App\Models\RouteLog;
use Tymon\JWTAuth\Exceptions\JWTException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Carbon\Carbon;
use Auth;
use Illuminate\Database\Eloquent\Builder;

use App\Notifications\NewUser as NewUserNotification;

use App\Traits\OneSignalMessages;

class TestController extends Controller
{
    use OneSignalMessages;
    
    /**
     * Create a new AuthController instance.
     *
     * @return void
     */
    public function __construct()
    {
    }

    
    
    public function test(Request $request) {
        /*
        $driver = Driver::with('user')->where('user_id', 6)->first();
        
        //$driver->kids()->attach($dataPost['kid_id']);
        $kid = Kid::findOrFail(17);
        
        $this->sendNotificationKidToDriver($driver->user, $kid);
        
        */
        
        /*
        
        $user = User::find(9);
        
        $user->notify(new NewUserNotification('user', 'user', 'pass'));
        
        */
        
        $id = 13;
        $driverId = 3;
        
        //$driverId = $request->input('driver_id');
        $driver = Driver::with('kids')->findOrFail($driverId);
        
        $assignedKids = $driver->kids->pluck('id'); 
        
        
        /*with('kids.school', 'kids.drivers')
        ->whereHas('kids', function (Builder $query) use ($assignedKids) {
            $query->whereNotIn('id', $assignedKids);
        })*/
        $user = User::with(['kids' => function($kids) use ($assignedKids) {
            return $kids->whereNotIn('id', $assignedKids);
        }])
        ->where('id', $id)
        ->first();
        
        return response()->json($user);
        
        return response()->json($user);
    }

} 