'Laravel - Passing id from one page and reference that id for the next page's table data
Good day. I'm having a hard time solving how to pass an id from a table (Region table) and use that id as a reference (idParent) for the table (Province table) on the next page. For context, all regions has an id, and the provinces has an idParent which is an id from regions.
I think I'm missing something in my routing, that's why I can't pass the data. Below are snippets of my blade file, Controller, and web.php. Thank you for helping.
web.php
// Masterlist Province
Route::get('province/{id}', [App\Http\Controllers\FormControllerMasterlistProvince::class, 'viewRecord'])->middleware('auth')->name('province');
Route::post('province.editprovince', [App\Http\Controllers\FormControllerMasterlistProvince::class, 'editprovince'])->name('province.editprovince');
Route::post('province.deleteprovince', [App\Http\Controllers\FormControllerMasterlistProvince::class, 'deleteprovince'])->name('province.deleteprovince');
FormControllerMasterlistProvince.php
// view record
public function viewRecord($id)
{
$data = DB::table('province')->where('idRegion', '=', $id)->get();
return view('province',compact('data'));
}
region.blade.php
@foreach ($data as $key => $item)
<tr>
<td class="text-center">
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle me-1" type="button"
id="dropdownMenuButton" data-bs-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
ACTION
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a href="{{ route('province') }}">
ㅤProvinceㅤ</a>
<a href="/province/{{ $item->id }}">
ㅤProvince (Test Button)ㅤ</a>
<a href="#" data-bs-toggle="modal" data-bs-target="#editregion"
data-myid="{{$item->id}}"
data-mytitle="{{$item->region}}">
Updateㅤ</span>
</a>
<a href="#" data-bs-toggle="modal" data-bs-target="#deleteregion"
data-myid="{{$item->id}}"
data-mytitle="{{$item->region}}">
Delete</a>
</div>
</div>
</div>
</td>
Should I be passing the id from the region controller to the province controller and also reference the id in the routing? Thank you for helping.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|