how to implement Laravel query from multiple tables using query() function?

  eloquent, laravel, mysql, php

I am new to laravel and building my first project using it. I want to query two tables (Cases and Detail) using orWhere() function. Please tell me the changes I need to make in my existing code.


$key = trim($request->get('q'));
$cases = Cases::query()
    ->where('cnic', "$key")
    ->orWhere('eventDate', "$key")            

return view('adminHome',['user' => $cases ]);

The field eventDate exists in the Detail Model.


<form action="/search" method="GET" role="search">
      <input type="number" name="q" placeholder="Search CNIC...">
      <input type="date" name="q" placeholder="Search CNIC..." ">
      <input type="Submit" name="Search" value="Search">
      {{ csrf_field() }}

Source: Laravel

Leave a Reply