'Search related table in Laravel 8 using Eloquent
I'm trying to search related table laravel 8.
$searchdata = TableA::where('id', '>', '1')->with('TableB')->orderBy('name');
if (request()->get('search')) {
$data = $data->where('name', 'LIKE', "%".request()->get('search')."%")
->orwhere('column1', "LIKE", "%".request()->get('search')."%")
->orwhere('column2', 'LIKE', "%".request()->get('search')."%");;
}
$data = $data->paginate(25);
return view('dashboard', compact('data')view('dashboard',compact('data')
It works like that. But I want to search also TableB.
search.blade.php
<form class="" method="GET" action="">
<div class="form">
<div class=" col-md-5 py-2 m-auto">
<input type="text" name="search" value="{{request()->get('search')}}"
placeholder="Search Data" class="form-control">
</div>
</div>
</form>
Table
<tbody>
@foreach ($data as $show)
<tr>
<td>{{$show->name}}</td>
<td>{{$show->column1}}</td>
<td>{{$show->column2}}</td>
<td>
<table class="table table-sm">
@foreach ($show->TableB as $o)
<tr>
<td><strong> {{$loop->iteration}}-</strong>
{{$o->xyz}} -
{{$o->abc}} -
{{$o->zxc}} -
{{$o->qwe}} -
{{$o->mnb}}
</tr>
@endforeach
</table>
</td>
</tr>
@endforeach
</tbody>
How can I search in TableB in this situation? I try or where, but it doesn't work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
