Arkadaşlar Laravel de pagination ve rows işlemleri ajax ile yapıyorum. Yani sayfa ilk açıldığında ajax ile paginate verileri çekiyor json formatında ve görüntülüyorum. Fakat burada örneğin yeni ekle butonuna tıklayıp create rotasına girip tarayıcıda yer alan back tuşunu kullandığımda sayfa json olarak görünüyor tamamı tarayıcıda. Kodlarımdan bölümler
CategoryController
public function index(Request $request)
{
$breadcrumbs = [
['title' => 'Anasayfa', 'url' => route('admin.dashboard')],
['title' => 'Katalog', 'url' => null],
['title' => 'Marka Listesi', 'url' => null]
];
$page = $request->input('page', 1);
$perPage = min($request->input('per_page', 20), 50);
$tableType = $request->input('table_type', 'brands_table');
$list = $this->brandService->all(
$page,
$perPage,
$request->all()
);
if ($request->ajax()) {
return response()->json([
'html' => view('admin_v1.components.datatable.rows.catalog.brands', [
'list' => $list
])->render(),
'pagination_html' => view('admin_v1.components.datatable.paginations.pagination', [
'paginator' => $list,
'paginator_name' => $tableType
])->render()
]);
}
$data = [
'pageTitle' => 'Marka Listesi',
'breadcrumbs' => $breadcrumbs,
'list' => $list,
'tableType' => $tableType,
'addRequestUrl' => route('admin.catalog.brands.create')
];
return view('admin_v1.catalog.brand.index', $data);
}
index.blade
<table id="brands_table" class="table table-bordered text-nowrap w-100">
<thead>
<tr>
<th style="max-width: 50px;">Marka No</th>
<th>Marka Adı</th>
<th>Durum</th>
<th style="max-width: 30px;">Sıra</th>
<th style="max-width: 30px;">#</th>
</tr>
</thead>
<tbody id="brands_table_tbody">
</tbody>
</table>
<div id="brands_table_pagination">
@include('admin_v1.components.datatable.paginations.pagination', [
'paginator' => $list,
'paginator_name' => 'brands_table',
])
</div>
@push('scripts')
<script>
const routeName = "{{ route('admin.catalog.brands.index') }}";
document.addEventListener('DOMContentLoaded', function () {
initDataTable('#brands_table');
initLoadData(routeName, '#brands_table', '#brands_table_pagination');
initPagination('brands_table', routeName, {
spinnerSelector: '#brands_spinner',
containerSelector: '#brands_table_pagination'
});
});
</script>
@endpush
route bilgileri
Route::prefix('brands')->name('brands.')->group(function () {
Route::get('/', [BrandsController::class, 'index'])->name('index');
Route::get('/create', [BrandsController::class, 'create'])->name('create');