passing firstChapter & lastChapter into PageControllerr

This commit is contained in:
Htet Phone Aung 2023-09-13 00:08:53 +06:30
parent b601f09cb2
commit d63979b5e3
15 changed files with 101 additions and 40 deletions

View File

@ -26,6 +26,7 @@ class LoginController extends Controller
* *
* @var string * @var string
*/ */
protected $redirectTo = RouteServiceProvider::HOME; protected $redirectTo = RouteServiceProvider::HOME;
/** /**

View File

@ -49,7 +49,7 @@ class ChapterController extends Controller
} else { } else {
//chapter number //chapter number
$manga = Manga::where('id', $request->manga_id)->first(); $manga = Manga::where('id', $request->manga_id)->first();
$latestChap = $manga->chapters()->latest()->first()->chapter_no; $latestChap = $manga->chapters()->orderBy('chapter_no', 'desc')->first()->chapter_no;
$formData['chapter_no'] = $latestChap + 1; $formData['chapter_no'] = $latestChap + 1;
} }

View File

@ -2,6 +2,8 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Manga;
use App\Models\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class HomeController extends Controller class HomeController extends Controller
@ -23,7 +25,11 @@ class HomeController extends Controller
*/ */
public function index() public function index()
{ {
return view('home'); $authors = User::where('role', 'author')->get();
$users = User::where('role', 'user')->get();
$mangas = Manga::all();
// dd($authors);
return view('home', ['authors' => $authors, 'users'=> $users, 'mangas' => $mangas]);
} }

View File

@ -26,11 +26,27 @@ class PageController extends Controller
public function manga($slug) public function manga($slug)
{ {
$manga = Manga::where('slug', $slug)->first(); $manga = Manga::where('slug', $slug)->first();
return view('manga', compact('manga')); $chapters = $manga->chapters()->orderBy('chapter_no', 'desc')->paginate(10);
$firstChapter = $manga->chapters()->orderBy('chapter_no', 'asc')->first();
$lastChapter = $manga->chapters()->latest('chapter_no')->first();
// dd($firstChapter);
return view('manga',[
'manga' => $manga,
'chapters' => $chapters,
'firstChapter' => $firstChapter,
'lastChapter' => $lastChapter
]);
} }
public function chapter(Manga $manga, Chapter $chapter) public function chapter(Manga $manga, Chapter $chapter)
{ {
return view('chapter_page', ['manga' => $manga, 'chapter' => $chapter]); $firstChapter = $manga->chapters()->orderBy('chapter_no', 'asc')->first();
$lastChapter = $manga->chapters()->latest('chapter_no')->first();
return view('chapter_page', [
'manga' => $manga,
'chapter' => $chapter,
'firstChapter' => $firstChapter,
'lastChapter' => $lastChapter
]);
} }
} }

View File

@ -20,6 +20,6 @@ class AppServiceProvider extends ServiceProvider
*/ */
public function boot(): void public function boot(): void
{ {
Paginator::useBootstrap(); Paginator::useBootstrapFive();
} }
} }

View File

@ -5,6 +5,7 @@ namespace App\Providers;
use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\RateLimiter; use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
@ -17,7 +18,7 @@ class RouteServiceProvider extends ServiceProvider
* *
* @var string * @var string
*/ */
public const HOME = '/'; public const HOME = "/";
/** /**
* Define your route model bindings, pattern filters, and other route configuration. * Define your route model bindings, pattern filters, and other route configuration.

View File

@ -22,3 +22,11 @@
.alert-msg { .alert-msg {
transform: translateX(-50%) translateY(10%); transform: translateX(-50%) translateY(10%);
} }
.cover-img {
transition: all 1s;
}
.cover-img:hover {
filter: grayscale(30%);
transform: scale(1.2);
}

View File

@ -1,26 +1,43 @@
@props(['manga']) @props(['manga', 'chapters', 'firstChapter', 'lastChapter'])
<div> <div>
<div class="text-center"> <h5 class="fw-semibold my-3 text-primary"> <i class="bi bi-award-fill"></i> {{ $manga->title }}</h5>
<img class="w-25" src="{{ asset('storage/' . $manga->cover) }}" alt=""> <div class="row my-3">
<div class="col-12 col-md-4">
<div class="text-center">
<img class="image-fluid" src="{{ asset('storage/' . $manga->cover) }}" alt="">
</div>
</div>
<div class="col-12 col-md-7">
<p> <span class="fw-semibold">Author</span> - {{ $manga->user->name }} </p>
<p> <span class="fw-semibold">Genre</span> - </p>
<p class="d-flex">
<a href="{{ route('page.chapter', [$manga->slug, $firstChapter->chapter_no]) }}" class="btn btn-primary me-1">Read First</a>
<a href="{{ route('page.chapter', [$manga->slug, $lastChapter->chapter_no]) }}" class="btn btn-primary">Read Last</a>
</p>
</div>
</div>
<div class="my-5">
<h5 class="fw-semibold text-primary"> <i class="bi bi-award-fill"></i> Summary </h5>
<hr>
<p class="text-black-50"> {{ $manga->summary }} </p>
</div> </div>
<h3 class="text-center my-3">{{ $manga->title }}</h3>
<p> {{ $manga->summary }} </p>
<ul class="list-group my-3 mt-5 mx-auto"> <ul class="list-group my-3 mt-5 mx-auto">
<h5 class="fw-bold mb-4"> <h5 class="w-semibold text-primary">
Latest Chapters <i class="bi bi-award-fill"></i> Latest Chapter Release
</h5> </h5>
@forelse ($manga->chapters()->orderBy('chapter_no', 'desc')->get() as $chapter) @forelse ($chapters as $chapter)
<a href="{{ route('page.chapter', [$manga->slug, $chapter->chapter_no]) }}" <a href="{{ route('page.chapter', [$manga->slug, $chapter->chapter_no]) }}"
class="list-group-item list-group-item-action pb-0 border-0 border-bottom class="list-group-item list-group-item-action pb-0 border-0 border-bottom
d-inline-block d-flex align-items-center justify-content-between"> d-inline-block d-flex align-items-center justify-content-between">
<p> Chapter {{ $chapter->chapter_no }} - {{ $chapter->title ?? '' }} </p> <p> Chapter {{ $chapter->chapter_no }} - {{ $chapter->title ?? '' }} </p>
<p class="text-black-50 small"> <p class="text-black-50 small">
{{$chapter->updated_at->diffForHumans()}} {{ $chapter->updated_at->diffForHumans() }}
</p> </p>
</a> </a>
@empty @empty
<p class="text-danger">No Chapter Yet!</p> <p class="text-danger">No Chapter Yet!</p>
@endforelse @endforelse
</ul> </ul>
{{ $chapters->links() }}
</div> </div>

View File

@ -2,14 +2,16 @@
<div class="col-6 col-md-3"> <div class="col-6 col-md-3">
<div class="card border-0"> <div class="card border-0">
<div class="text-center"> <div class="text-center overflow-hidden">
<a href="{{ route('page.manga', $manga->slug) }}"> <a href="{{ route('page.manga', $manga->slug) }}">
<img src="{{ asset( 'storage/'.$manga->cover ) }}" alt="img" <img src="{{ asset( 'storage/'.$manga->cover ) }}" alt="img"
class="w-100"> class="w-100 cover-img">
</a> </a>
</div> </div>
<div class="mt-2"> <div class="mt-2">
<h5 class="fw-semibold "> {{ $manga->title }} </h5> <a href="{{ route('page.manga', $manga->slug) }}" class="text-decoration-none">
<h5 class="fw-semibold "> {{ $manga->title }} </h5>
</a>
@forelse ($manga->chapters()->latest('id')->limit(2)->get() as $chapter) @forelse ($manga->chapters()->latest('id')->limit(2)->get() as $chapter)
<x-latest-chapter :manga="$manga" :chapter="$chapter" /> <x-latest-chapter :manga="$manga" :chapter="$chapter" />
@empty @empty

View File

@ -12,6 +12,11 @@
@endif @endif
{{ __('You are logged in!') }} {{ __('You are logged in!') }}
<h5 class="text-primary fw-semibold mt-3"> <i class="bi bi-arrow-through-heart-fill"></i> Statistics</h5>
<p>Authors : <span class="text-success">{{ $authors->count() }} {{ Str::plural('author', $authors->count())}} </span></p>
<p>Users : <span class="text-success">{{ $users->count() }} {{ Str::plural('user', $authors->count()) }}</span> </p>
<p>Comics : <span class="text-success">{{ $mangas->count() }} {{ Str::plural('comic', $mangas->count()) }}</span> </p>
</div> </div>
</div> </div>
@endsection @endsection

View File

@ -9,7 +9,7 @@
<a title="clear search" href="{{ route('page.index') }}" class="btn btn-danger ms-4 p-0 px-1 border-1 border-dark"> <i class="bi bi-x-lg"></i> </a> <a title="clear search" href="{{ route('page.index') }}" class="btn btn-danger ms-4 p-0 px-1 border-1 border-dark"> <i class="bi bi-x-lg"></i> </a>
</div> </div>
@endif @endif
<div class="col-12 col-md-9"> <div class="col-12 col-md-9 mb-4">
<div class="row flex-wrap"> <div class="row flex-wrap">
@forelse ($mangas as $manga) @forelse ($mangas as $manga)
<x-outter-manga-frame :manga="$manga" /> <x-outter-manga-frame :manga="$manga" />
@ -23,8 +23,8 @@
</div> </div>
</div> </div>
<hr class="d-block d-md-none w-75 mx-auto text-primary">
<div class="col-12 col-md-3"> <div class="col-12 col-md-3 mb-4">
@include('partials.hot-manga') @include('partials.hot-manga')
</div> </div>
<div class="col-12 mt-5"> <div class="col-12 mt-5">

View File

@ -6,7 +6,7 @@
<div class="row mt-5"> <div class="row mt-5">
<div class="col-12 col-md-9"> <div class="col-12 col-md-9">
<x-inner-manga :manga="$manga" /> <x-inner-manga :manga="$manga" :chapters="$chapters" :firstChapter="$firstChapter" :lastChapter="$lastChapter" />
</div> </div>
<div class="col-12 col-md-3"> <div class="col-12 col-md-3">

View File

@ -1,15 +1,15 @@
<div> <div>
<a <a
href="{{ route('page.chapter', [$manga->slug, $chapter->chapter_no - 1 ]) }}" href="{{ route('page.chapter', [$manga->slug, $chapter->chapter_no - 1 ]) }}"
class="btn btn-{{$chapter->chapter_no == 1 ? 'secondary' : 'dark' }} btn-small {" class="btn btn-{{$chapter->chapter_no == $firstChapter->chapter_no ? 'secondary' : 'dark' }} btn-small {"
style="pointer-events: {{ $chapter->chapter_no == 1 ? 'none' : '' }}"> style="pointer-events: {{ $chapter->chapter_no == $firstChapter->chapter_no ? 'none' : '' }}">
Previous Previous
</a> </a>
{{-- <p> {{ }} </p> --}}
<a <a
href="{{ route('page.chapter', [$manga->slug, $chapter->chapter_no + 1 ]) }}" href="{{ route('page.chapter', [$manga->slug, $chapter->chapter_no + 1 ]) }}"
class="btn btn-{{ $chapter->chapter_no == $manga->chapters->last()->chapter_no ? 'secondary' : 'dark' }} btn-small" class="btn btn-{{ $chapter->chapter_no == $lastChapter->chapter_no ? 'secondary' : 'dark' }} btn-small"
style="pointer-events: {{ $chapter->chapter_no == $manga->chapters->last()->chapter_no ? 'none' : '' }}" style="pointer-events: {{ $chapter->chapter_no == $lastChapter->chapter_no ? 'none' : '' }}">
>
Next Next
</a> </a>
</div> </div>

View File

@ -1,21 +1,23 @@
<h4 class="fw-semibold">Manga Hot</h4> <h5 class="fw-semibold text-primary"> <i class="bi bi-award-fill"></i> Manga Hot</h5>
<div class="row"> <div class="row">
@forelse (App\Models\Manga::latest('id')->limit(3)->get() as $hotManga) @forelse (App\Models\Manga::latest('id')->limit(3)->get() as $hotManga)
<div class="col-12 mt-3"> <div class="col-12 mt-3">
<div class="d-flex border-0"> <div class="row border-0 flex-wrap">
<div> <div class="overflow-hidden col-4">
<a href="{{ route('page.manga', $hotManga->slug) }}"> <a href="{{ route('page.manga', $hotManga->slug) }}">
<img src="{{ asset( 'storage/'.$hotManga->cover) }}" <img src="{{ asset( 'storage/'.$hotManga->cover) }}"
alt="img" style="max-width: 80px"> alt="img" class="cover-img img-fluid">
</a> </a>
</div> </div>
<div class="ms-2"> <div class="col-8">
<p class="fw-semibold mb-1"> {{ $hotManga->title }} </p> <a href="{{ route('page.manga', $hotManga->slug) }}" class="text-decoration-none">
<p class="fw-semibold mb-1"> {{ $hotManga->title }} </p>
</a>
@foreach ($hotManga->chapters()->latest('id')->limit(2)->get() as $hotChap) @foreach ($hotManga->chapters()->latest('id')->limit(2)->get() as $hotChap)
<x-latest-chapter :manga="$hotManga" :chapter="$hotChap" /> <x-latest-chapter :manga="$hotManga" :chapter="$hotChap" />
@endforeach @endforeach
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,4 +1,7 @@
<ul class="list-group"> <ul class="list-group">
<h5>
<a href="{{ route('home') }}" class="list-group-item list-group-item-action text-primary"><i class="bi bi-speedometer2"></i> Dashboard </a>
</h5>
<h5>Manga</h5> <h5>Manga</h5>
<a href="{{ route('manga.index') }}" class="list-group-item list-group-item-action"><i class="bi bi-book"></i> Manga <a href="{{ route('manga.index') }}" class="list-group-item list-group-item-action"><i class="bi bi-book"></i> Manga
List </a> List </a>