<?php

namespace App\Http\Main\Engineers\Drive;

use App\Models\Drive;
use App\Models\User;
use Livewire\Component;

class Index extends Component
{


    public $queryString = ['q'];
    public $q;

    public function mount()
    {
    }


    public function render()
    {
        if ($this->q == '') {
            $drives = Drive::all();
        } else {
            $user= User::where('phone', $this->q)->get()->first();
            $drives = Drive::orWhere('iaea_no', 'LIKE', '%' . $this->q . '%')->orWhere('serial_no', 'LIKE', '%' . $this->q . '%');
            if($user!=null){
                $drives = $drives->orWhere('user_id',$user->id);
            }
            $drives = $drives->get();
        }
        return view('main.engineers.drive.index', [
            'drives' => $drives
        ])->layout('layouts.app-engineers');
    }
}
