Hello guys I'm new to Laravel and programming.
This is my controller here I'm trying to get all the Reference ['1','2','3',etc.] from MasterListing table. I also have a reference column in DetailListing table(2nd line).
public function show(DetailListing $id)
{
$d = \App\MasterListing::pluck('Reference');
$data = \App\DetailListing::where('reference',$d)->get();
return view('detaillisting',['data'=>$data]);
}
master listing page(https://i.stack.imgur.com/p4s5A.jpg), HTML for master listing page
<tbody>
@foreach ($data as $row)
<tr>
<td> {{ $row->id }} </td>
<td> {{ $row->Name }} </td>
<td> {{ $row->Description }} </td>
<td> {{ $row->Type }} </td>
<td><button class="btn btn-success" onclick="location.href = 'detaillisting/{{ $row->id }}';">BROWSE</button></td>
</tr>
@endforeach
</tbody>
Route
Route::get('/detaillisting/{id}','DetailTestController@show');
What I expect is when I click on #1 BROWSE, it should redirect me to detail listing page and show DetailListing data with only reference '1', when I click on #2 BROWSE it should only show data with reference '2', etc.
But it resulted showing all data with reference '1' no matter I click on which button.
This has troubled me for a long time, really appreciate your help!
From your route I see you are not passing an object if type DetailListing but an int or a string, I suppose this is the reference value in detailListing table?
public function show($id)
{
$data = \App\DetailListing::where('reference',$id)->get();
return view('detaillisting',['data'=>$data]);
}