select box onchange-submit and go to the specific chapter

This commit is contained in:
Htet Phone Aung 2023-09-13 00:50:43 +06:30
parent d63979b5e3
commit 27cd37bcfe
4 changed files with 23 additions and 7 deletions

View File

@ -38,7 +38,7 @@ class PageController extends Controller
]);
}
public function chapter(Manga $manga, Chapter $chapter)
public function chapter(Manga $manga,Chapter $chapter)
{
$firstChapter = $manga->chapters()->orderBy('chapter_no', 'asc')->first();
$lastChapter = $manga->chapters()->latest('chapter_no')->first();
@ -49,4 +49,10 @@ class PageController extends Controller
'lastChapter' => $lastChapter
]);
}
public function select(Manga $manga, Request $request)
{
// dd($request);
return redirect()->route('page.chapter', [$manga, $request->chapter_no]);
}
}

View File

@ -1 +1,6 @@
import './bootstrap';
// let selectChapter = document.querySelector('#selectChapter');
// selectChapter.addEventListener('change', function() {
// this.submit();
// });

View File

@ -1,8 +1,12 @@
<div class="col-4">
<select name="" id="" class="form-select">
@foreach ($manga->chapters()->latest('id')->get() as $chap)
<option value="{{ $chap->id }}" {{ $chap->id == $chapter->id ? 'selected' : '' }}>
Chapter {{ $chap->chapter_no }} - {{ $chap->title ?? '' }} </option>
<form action="{{route('select.chapter', [$manga->slug])}}" method="post" id="selectChapter" onchange="this.submit();">
@csrf
<select name="chapter_no" class="form-select">
@foreach ($manga->chapters()->latest('chapter_no')->get() as $chap)
<option value="{{ $chap->chapter_no }}" {{ $chap->chapter_no == $chapter->chapter_no ? 'selected' : '' }}>
Chapter {{ $chap->chapter_no }} - {{ $chap->title ?? '' }}
</option>
@endforeach
</select>
</form>
</div>

View File

@ -24,6 +24,7 @@ Route::controller(PageController::class)->group(function () {
Route::get('/', 'index')->name('page.index');
Route::get('/MangaDex/manga/{slug}', 'manga')->name('page.manga');
Route::get('/manga/{manga:slug}/chapter/{chapter:chapter_no?}', 'chapter')->name('page.chapter');
Route::post('/manga/{manga:slug}/select', 'select')->name('select.chapter');
});
Auth::routes();