Pracuję z PHP (Laravel 5.3) i rozwijam widok Blade z modalem Bootstrap, który ma wewnątrz pętlę foreach, aby pokazać zbyt wiele wierszy. Ten modal jest wywoływany z tabeli, która na końcu każdego wiersza ma przycisk, aby uzyskać więcej szczegółów (a te szczegóły są tablicą).
Jak więc mogę przekazać dane tablicy do modalu?
<div class="table-responsive">
<table class="table table-bordered m-table" id="business">
<thead class="columns">
<tr>
<th class="column1">Name</th>
<th class="column2">Contact</th>
<th class="column3">Details</th>
</tr>
</thead>
<tbody class="main-rows list" >
@foreach ($listBusiness as $business)
<tr>
<td class="column1">{{$business->name}}</td>
<td class="column2">{{$business->contact}}</td>
<td class="column7">
<a data-toggle="modal" data-target="#modalBusinessDetails">
<i class="la la-search"></i>
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<!-- Modal table -->
<div class="modal" id="modalBusinessDetails" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body text-center">
<div class="col-12">
<div class="table-responsive">
<table class="table table-bordered m-table" id="business">
<thead class="columns">
<tr>
<th class="column1">Created at</th>
<th class="column2">Active</th>
<th class="column2">Employees</th>
</tr>
</thead>
<tbody class="main-rows">
@foreach ($ListDetail as $BusinessDetail)
<tr>
<td class="column1">{{$BusinessDetail->created_at}}</td>
<td class="column2">{{$BusinessDetail->active}}</td>
<td class="column3 text-center">{{$BusinessDetail->employees}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<div class="btn group">
<button type="button" data-dismiss="modal">{{Tr('Close')}}</button>
</div>
</div>
</div>
</div>
</div>
0
Ferran Muñoz
19 listopad 2019, 15:52
2
Będziesz musiał użyć javascript, aby zmienić zawartość modal
– Vidal
19 listopad 2019, 15:56
Lub utwórz wiele modów (niezalecane)
– delboy1978uk
19 listopad 2019, 15:57
Dlatego jest AJAX, na swoim przycisku umieść identyfikator w funkcji i po kliknięciu tego przycisku możesz wykonać wywołanie AJAX, aby pobrać więcej danych z bazy danych
– BlackXero
19 listopad 2019, 16:26
1 odpowiedź
Tak jak powiedział @Vidal, wymaga to JS (takich jak AJAX, AXIOS itp.) Oto moja przykładowa metoda kontrolera, której możesz użyć do czegoś takiego.
function getData(Request $request)
{
$data = DB::table('table_name')->get(); //can be done differently
//create separate view for dynamic data e.g table <tbody>AJAX or AXIOS response</tbody>
$returnHTML = view('view_name',compact('data'))->render();
return response()->json( ['success' => true, 'html' => $returnHTML] );
}
Mam nadzieję, że to pomoże.
1
EarnP
19 listopad 2019, 17:00