added policies

This commit is contained in:
Htet Phone Aung 2023-09-06 14:37:03 +06:30
parent 6d05b8c45b
commit 0c13543c28
42 changed files with 475 additions and 289 deletions

View File

@ -41,7 +41,9 @@ class ChapterController extends Controller
}
$formData['images'] = $images;
}
//chapter number
$manga = Manga::where('id', $request->manga_id)->first();
$formData['chapter_no'] = $manga->chapters->count() + 1;
Chapter::create($formData);
return redirect()->route('home')->with(['message' => 'New Chapter has been added!!']);
@ -77,6 +79,7 @@ class ChapterController extends Controller
*/
public function destroy(Chapter $chapter)
{
$this->authorize('delete', $chapter);
$chapter->delete();
return back()->with(['message' => "Successfully Deleted!"]);
}

View File

@ -13,7 +13,7 @@ class HomeController extends Controller
*/
public function __construct()
{
$this->middleware('auth');
$this->middleware(['auth', 'admin.access']);
}
/**
@ -26,5 +26,5 @@ class HomeController extends Controller
return view('home');
}
}

View File

@ -61,6 +61,8 @@ class MangaController extends Controller
*/
public function edit(Manga $manga)
{
$this->authorize('update', $manga);
return view('manga.edit', compact('manga'));
}
@ -69,6 +71,8 @@ class MangaController extends Controller
*/
public function update(UpdateMangaRequest $request, Manga $manga)
{
$this->authorize('update', $manga);
$formData = $request->validated();
$formData['slug'] = Str::slug($request->title);
$formData['excerpt'] = Str::words($request->summary, 10, '...');
@ -85,6 +89,8 @@ class MangaController extends Controller
*/
public function destroy(Manga $manga)
{
$this->authorize('delete', $manga);
$manga->delete();
return redirect()->back()->with(['message' => 'Manga has been deleted!']);
}

View File

@ -10,11 +10,9 @@ class PageController extends Controller
{
public function index()
{
$mangas = Manga::latest('id')->paginate(10)->withQueryString();
$hotMangas = Manga::latest('id')->limit('3')->get();
$mangas = Manga::latest('id')->paginate(8)->withQueryString();
return view('index', [
'mangas' => $mangas,
'hotMangas' => $hotMangas
'mangas' => $mangas
]);
}
@ -24,9 +22,8 @@ class PageController extends Controller
return view('manga', compact('manga'));
}
public function chapter(Manga $manga, Chapter $chapter )
public function chapter(Manga $manga, Chapter $chapter)
{
return view('chapter_page', ['manga' => $manga, 'chapter' => $chapter]);
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
public function index()
{
// $this->authorize('admin-only', Auth::user()->role);
$users = User::latest('id')->paginate(10)->withQueryString();
return view('user.index', compact('users'));
}
}

View File

@ -2,6 +2,7 @@
namespace App\Http;
use App\Http\Middleware\AdminAccess;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
@ -21,6 +22,8 @@ class Kernel extends HttpKernel
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
AdminAccess::class
];
/**
@ -64,5 +67,6 @@ class Kernel extends HttpKernel
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'admin.access' => AdminAccess::class
];
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class AdminAccess
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
//prevent normal users form accessing admin dashboard
if(Auth::user()) {
if(Auth::user()->role == "user") {
return redirect()->route('page.index')->with(['message' => 'You are not an admin!!']);
}
}
return $next($request);
}
}

View File

@ -23,7 +23,8 @@ class StoreMangaRequest extends FormRequest
{
return [
'title' => 'required|min:3|max:100',
'summary' => 'required|min:3'
'summary' => 'required|min:3',
'cover' => 'required|file'
];
}
}

View File

@ -9,7 +9,7 @@ class Chapter extends Model
{
use HasFactory;
protected $fillable = ['title', 'images', 'manga_id', 'user_id'];
protected $fillable = ['title', 'images', 'manga_id', 'user_id', 'chapter_no'];
protected $casts = [
'images' => 'array'
];

View File

@ -42,4 +42,9 @@ class User extends Authenticatable
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
public function mangas()
{
return $this->hasMany(Manga::class, 'author_id');
}
}

View File

@ -8,6 +8,14 @@ use Illuminate\Auth\Access\Response;
class ChapterPolicy
{
//access all to admin
public function before(User $user)
{
if($user->role === 'admin') {
return true;
}
}
/**
* Determine whether the user can view any models.
*/
@ -45,7 +53,7 @@ class ChapterPolicy
*/
public function delete(User $user, Chapter $chapter): bool
{
//
return $user->id == $chapter->user_id;
}
/**

View File

@ -11,9 +11,19 @@ class MangaPolicy
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
//access all to admin
public function before(User $user)
{
//
if($user->role === 'admin') {
return true;
}
}
public function viewAny(User $user, Manga $manga): bool
{
// return $user->id == $manga->author_id;
}
/**
@ -21,7 +31,7 @@ class MangaPolicy
*/
public function view(User $user, Manga $manga): bool
{
//
return $user->id == $manga->author_id;
}
/**
@ -37,7 +47,7 @@ class MangaPolicy
*/
public function update(User $user, Manga $manga): bool
{
//
return $user->id == $manga->author_id;
}
/**
@ -45,7 +55,7 @@ class MangaPolicy
*/
public function delete(User $user, Manga $manga): bool
{
//
return $user->id == $manga->author_id;
}
/**

View File

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

View File

@ -3,6 +3,13 @@
namespace App\Providers;
// use Illuminate\Support\Facades\Gate;
use App\Models\User;
use App\Models\Manga;
use App\Models\Chapter;
use App\Policies\MangaPolicy;
use App\Policies\ChapterPolicy;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
@ -13,7 +20,8 @@ class AuthServiceProvider extends ServiceProvider
* @var array<class-string, class-string>
*/
protected $policies = [
//
Manga::class => MangaPolicy::class,
Chapter::class => ChapterPolicy::class
];
/**
@ -21,6 +29,7 @@ class AuthServiceProvider extends ServiceProvider
*/
public function boot(): void
{
//
//gates here
Gate::define('admin-only', fn(User $user) => $user->role === 'admin');
}
}

View File

@ -17,7 +17,7 @@ class RouteServiceProvider extends ServiceProvider
*
* @var string
*/
public const HOME = '/home';
public const HOME = '/';
/**
* Define your route model bindings, pattern filters, and other route configuration.

View File

@ -20,6 +20,7 @@ class ChapterFactory extends Factory
for ($i = 0; $i < 10; $i++) {
$images[] = fake()->imageUrl(400,400,'cats');
}
return [
'title' => fake()->title(),
'images' => $images,

View File

@ -15,7 +15,7 @@ return new class extends Migration
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->enum('role', ['user', 'admin'])->default('user');
$table->enum('role', ['user', 'author', 'admin'])->default('user');
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();

View File

@ -14,6 +14,7 @@ return new class extends Migration
Schema::create('chapters', function (Blueprint $table) {
$table->id();
$table->string('title')->nullable();
$table->unsignedInteger('chapter_no')->nullable();
$table->json('images');
$table->foreignId('manga_id')->constrained()->onDelete('cascade');
$table->foreignId('user_id');

View File

@ -1,33 +1,43 @@
@extends('layouts.app')
@section('content')
<form method="POST" action="{{route('chapter.store')}}" enctype="multipart/form-data">
@csrf
<div class="mb-3">
<label for="">Choose Manga</label>
<select name="manga_id" id="" class="form-select">
<option>Select Manga</option>
@foreach (App\Models\Manga::latest('id')->get() as $manga)
<option value="{{$manga->id}}" {{ $manga->id == request()->manga_id ? 'selected' : ''}}> {{$manga->title}} </option>
@endforeach
</select>
@error('manga_id')
<p class="text-danger small">{{ $message }}</p>
@enderror
</div>
<div class="mb-3">
<label for="">Chapter Title <span class="text-danger">*Optinal</span></label>
<input type="text" name="title" class="form-control">
@error('title')
<p class="text-danger small">{{ $message }}</p>
@enderror
<x-card-card-body>
<div class="mb-4">
<a title="back" href="{{ url()->previous() }}" class="btn btn-dark"> <i class="bi bi-arrow-left"></i> </a>
<a href="{{ route('chapter.index') }}" class="btn btn-dark"> <i class="bi bi-book"></i> Chapter List</a>
</div>
<form method="POST" action="{{ route('chapter.store') }}" enctype="multipart/form-data">
@csrf
<div class="mb-3">
<label for="">Choose Manga</label>
<select name="manga_id" id="" class="form-select">
<option>Select Manga</option>
@foreach (App\Models\Manga::latest('id')->get() as $manga)
<option value="{{ $manga->id }}"
{{ $manga->id == request()->manga_id ? 'selected' : '' }}
>
{{ $manga->title }} </option>
@endforeach
</select>
@error('manga_id')
<p class="text-danger small">{{ $message }}</p>
@enderror
</div>
<div class="mb-3">
<label for="">Chapter Title <span class="text-danger">*Optinal</span></label>
<input type="text" name="title" class="form-control">
@error('title')
<p class="text-danger small">{{ $message }}</p>
@enderror
</div>
<div class="mb-3">
<label for="">Chapter Images</label>
<input type="file" name="images[]" id="" class="form-control" multiple>
</div>
<div class="mb-3">
<label for="">Chapter Images</label>
<input type="file" name="images[]" id="" class="form-control" multiple>
</div>
<button type="submit" class="btn btn-outline-dark">Create</button>
</form>
<button type="submit" class="btn btn-outline-dark">Create</button>
</form>
</x-card-card-body>
@endsection

View File

@ -2,18 +2,20 @@
@section('content')
<div class="row">
<h3>Choose Your Manga and See Chapters</h3>
<hr>
@foreach ($mangas as $manga)
<div class="col-6 col-md-3 mb-4">
<div class="col-6 col-md-4 col-lg-3 mb-4">
<a class="text-decoration-none" href="{{ route('chapters.manage', $manga->slug) }}">
<card class="card card-body">
<div>
<img src="{{ asset($manga->cover) }}" class="w-100" alt="">
<div class="card card-body" style="min-height: 400px">
<div class="">
<img src="{{ asset( 'storage/'.$manga->cover) }}" class="img-fluid rounded" alt="">
</div>
<p class="fw-semibold mt-2 mb-0"> {{ $manga->title }} </p>
<p class="fw-semibold mt-2 mb-1"> {{ $manga->title }} </p>
<p class="text-black-50 small">Total Chapter :
<span class="bg-warning p-1 py-0 rounded-circle"> {{ $manga->chapters->count() }} </span>
</p>
</card>
</div>
</a>
</div>
@endforeach

View File

@ -7,12 +7,15 @@
</div>
<h3> {{ $manga->title }} </h3>
<hr>
<h5> Chapters </h5>
<div class="d-flex mb-4">
<h5> Manage Your Chapters </h5> <a href="{{route('chapter.create',['manga_id' => $manga->id])}}" title="Add New Chapter" class="btn btn-sm btn-outline-dark ms-2 rounded-circle"> <i class="bi bi-plus"></i> </a>
</div>
<div class="row">
@foreach ($manga->chapters()->latest('id')->get() as $chapter)
@foreach ($manga->chapters()->latest('id')->paginate(20) as $chapter)
<div class="col-2">
<div class="d-flex p-2 border border-1 border-dark rounded align-items-center justify-content-between mb-3">
<p class="small mb-0"> {{ $chapter->title }} </p>
<p class="small mb-0"> Chapter {{ $chapter->chapter_no }} </p>
<div class="btn-group">
<form method="POST" action="{{ route('chapter.destroy', $chapter->id) }}">
@csrf

View File

@ -3,55 +3,27 @@
<h3 class="fw-semibold my-4"> {{ $manga->title }} - {{ $chapter->title }} </h3>
<div class="text-center mx-auto my-5">
{{-- breadcrumb --}}
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item text-decoration-none"><a href="{{ route('page.index') }}">Home</a></li>
<li class="breadcrumb-item text-decoration-none"><a href="{{ route('page.manga', $manga->slug) }}">
{{ $manga->title }} </a></li>
<li class="breadcrumb-item active" aria-current="page">Chapter {{ $chapter->id }} </li>
</ol>
</nav>
@include('partials.chapter-breadcrumb')
{{-- select box and paginate --}}
<div class="my-4 d-flex justify-content-between">
<div class="col-4">
<select name="" id="" class="form-select bg-dark text-white">
@foreach ($manga->chapters()->latest('id')->get() as $chap)
<option value="{{ $chap->id }}" {{ $chap->id == $chapter->id ? 'selected' : '' }}>
{{ $chap->title }} </option>
@endforeach
</select>
</div>
<div>
<a href="" class="btn btn-dark btn-small">Previous</a>
<a href="" class="btn btn-dark btn-small">Next</a>
</div>
@include('partials.chapter-select-box')
@include('partials.chapter-paginate')
</div>
{{-- manga images --}}
<div class="mb-4">
@foreach ($chapter->images as $image)
<img src="{{ asset($image) }}" class="mx-auto w-50 my-0" alt="">
<img src="{{ asset('storage/'.$image) }}" class="mx-auto w-50 my-0" alt="">
@endforeach
</div>
<hr>
{{-- chapters and pagiantion --}}
<div class="my-5 d-flex justify-content-between">
<div class="col-4">
<select name="" id="" class="form-select bg-dark text-white">
@foreach ($manga->chapters()->latest('id')->get() as $chap)
<option value="{{ $chap->id }}" {{ $chap->id == $chapter->id ? 'selected' : '' }}>
{{ $chap->title }} </option>
@endforeach
</select>
</div>
<div>
<a href="" class="btn btn-dark btn-small">Previous</a>
<a href="" class="btn btn-dark btn-small">Next</a>
{{-- {{ $allChap->links() }} --}}
</div>
<div class="my-4 d-flex justify-content-between">
@include('partials.chapter-select-box')
@include('partials.chapter-paginate')
</div>
</div>
@endsection

View File

@ -0,0 +1,5 @@
<div class="card">
<div class="card-body">
{{$slot}}
</div>
</div>

View File

@ -1,3 +1,3 @@
<div class="bg-dark py-5 mt-5">
<div class="bg-dark py-4 mt-5">
<p class="text-center fw-bold text-white">Copyright All Served @MangaDex</p>
</div>

View File

@ -0,0 +1,26 @@
@props(['manga'])
<div>
<div class="text-center">
<img class="w-25" src="{{ asset('storage/' . $manga->cover) }}" alt="">
</div>
<h3 class="text-center my-3">{{ $manga->title }}</h3>
<p> {{ $manga->summary }} </p>
<ul class="list-group my-3 mt-5 mx-auto">
<h5 class="fw-bold mb-4">
Latest Chapters
</h5>
@forelse ($manga->chapters()->latest('id')->get() as $chapter)
<a href="{{ route('page.chapter', [$manga->slug, $chapter->id]) }}"
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">
<p> Chapter {{ $chapter->chapter_no }} - {{ $chapter->title ?? '' }} </p>
<p class="text-black-50 small">
{{$chapter->updated_at->diffForHumans()}}
</p>
</a>
@empty
<p class="text-danger">No Chapter Yet!</p>
@endforelse
</ul>
</div>

View File

@ -0,0 +1,9 @@
@props(['manga', 'chapter'])
<div class="d-flex justify-content-between flex-wrap mb-2">
<a href="{{ route('page.chapter', [$manga->slug, $chapter->id]) }}"
class="text-decoration-none text-white small bg-secondary rounded-pill px-1">
Chapter {{ $chapter->chapter_no }}
</a>
<span class="small ms-1"> {{ $chapter->created_at->diffForHumans() }} </span>
</div>

View File

@ -0,0 +1,69 @@
@props(['mangas'])
<h5>Manga List</h5>
<hr>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col" style="min-width: 20%">Title</th>
<th>Author</th>
<th scope="col">Total Chapters</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
@forelse ($mangas as $manga)
<tr>
<th scope="row"> {{ $manga->id }} </th>
<td>
<p class="mb-0">{{ $manga->title }}</p>
<span class="small text-black-50">{{ $manga->excerpt }}</span>
</td>
<td>
{{ $manga->user->name }}
</td>
<td class="text-center">
{{ $manga->chapters->count() }}
</td>
<td>
<div class="btn-group">
@can('view', $manga)
<a href="{{ route('manga.show', $manga->slug) }}" class="btn btn-outline-dark"><i
class="bi bi-exclamation-diamond"></i>
</a>
@endcan
@can('update', $manga)
<a href="{{ route('manga.edit', $manga->id) }}" class="btn btn-outline-dark" title="edit">
<i class="bi bi-pencil-square"></i>
</a>
@endcan
@can('delete', $manga)
<button class="btn btn-outline-dark" form="deleteForm{{ $manga->id }}" title="delete"
onclick="return confirm('Are sure to delete?')">
<i class="bi bi-trash3"></i>
</button>
@endcan
</div>
<form method="post" id="deleteForm{{ $manga->id }}"
action="{{ route('manga.destroy', $manga->id) }}" class="d-inline-block">
@csrf
@method('delete')
</form>
</td>
</tr>
@empty
<p class="text-danger">No Manga Yet</p>
@endforelse
</tbody>
</table>
</div>
<div class="">
{{ $mangas->links() }}
</div>

View File

@ -0,0 +1,20 @@
@props(['manga'])
<div class="col-6 col-md-3">
<div class="card border-0">
<div class="text-center">
<a href="{{ route('page.manga', $manga->slug) }}">
<img src="{{ asset( 'storage/'.$manga->cover ) }}" alt="img"
class="w-100">
</a>
</div>
<div class="mt-2">
<h5 class="fw-semibold "> {{ $manga->title }} </h5>
@forelse ($manga->chapters()->latest('id')->limit(2)->get() as $chapter)
<x-latest-chapter :manga="$manga" :chapter="$chapter" />
@empty
<p class="small text-danger">No Chapter Yet</p>
@endforelse
</div>
</div>
</div>

View File

@ -5,65 +5,27 @@
<div class="row mt-5">
<div class="col-12 col-md-9">
<div class="row flex-wrap">
@foreach ($mangas as $manga)
<div class="col-6 col-md-3">
<div class="card border-0">
<div class="text-center">
<a href="{{ route('page.manga', $manga->slug) }}">
<img src="{{ asset( $manga->cover ) }}" alt="img"
class="w-100">
</a>
</div>
<div class="mt-2">
<h5 class="fw-semibold "> {{ $manga->title }} </h5>
@forelse ($manga->chapters()->latest('id')->limit(2)->get() as $chapter)
<a href="{{ route('page.chapter', [$chapter->manga->slug, $chapter->id]) }}"
class="d-block text-decoration-none text-white d-flex justify-content-between flex-wrap my-2">
<span class=" bg-secondary rounded-pill small py-0 px-2">
{{ $chapter->title }}
</span>
<span class="small text-black-50">
{{ $chapter->created_at->diffforhumans() }}
</span>
</a>
@forelse ($mangas as $manga)
<x-outter-manga-frame :manga="$manga" />
@empty
<p class="text-center text-danger">No Manga Yet</p>
@endforelse
@empty
@endforelse
</div>
</div>
</div>
@endforeach
{{-- <div class="col-6 col-md-3">
<div class="card border-0">
<div class="text-center">
<img src="{{ asset('img/sample.jpg') }}" alt="img" class="w-100 ">
</div>
<div class="mt-2">
<h5 class="fw-semibold ">The Villainous Desciple</h5>
<div class="d-flex justify-content-between flex-wrap mb-1">
<a href=""
class="text-decoration-none text-white bg-secondary rounded-pill py-0 px-2">Chapter
5</a>
<span class=" fs-6">5 mins ago</span>
</div>
<div class="d-flex justify-content-between flex-wrap mb-1">
<a href=""
class="text-decoration-none text-white bg-secondary rounded-pill py-0 px-2">Chapter
4</a>
<span class=" fs-6">4 mins ago</span>
</div>
</div>
</div>
</div> --}}
</div>
</div>
<div class="col-12 col-md-3">
@include('partials.hot-manga')
</div>
<div class="col-12 mt-5">
<div class="float-end">
{{ $mangas->links() }}
</div>
</div>
</div>
@endsection
@endsection
@section('footer')
@include('partials.footer')
<x-footer />
@endsection

View File

@ -12,16 +12,19 @@
</head>
<body>
<!-- Header Here -->
@include('partials.nav')
@include('partials.patreon-nav')
<!-- Header Here -->
@include('partials.nav')
@include('partials.patreon-nav')
<!-- Content Here -->
<div class="main container">
@yield('content')
</div>
<!-- Content Here -->
<div class="main container">
@yield('content')
</div>
@include('partials.alert-msg')
@yield('footer')
@yield('footer')
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
</body>

View File

@ -1,28 +1,20 @@
@extends('layouts.master')
@section('content')
<a href="{{ url()->previous() }}" class="btn btn-dark">Back</a>
<div>
<div class="text-center">
<img class="w-25" src="{{ $manga->cover ? asset( $manga->cover) : '' }}" alt="">
@include('partials.manga-breadcrum')
<div class="row mt-5">
<div class="col-12 col-md-9">
<x-inner-manga :manga="$manga" />
</div>
<div class="col-12 col-md-3">
@include('partials.hot-manga')
</div>
<h3 class="text-center my-3">{{ $manga->title }}</h3>
<p> {{ $manga->summary }} </p>
<ul class="list-group my-3 mt-5 text-center w-50 mx-auto">
<h5 class="fw-bold mb-3">
Chapters
</h5>
@forelse ($manga->chapters()->latest('id')->get() as $chapter)
<a href="{{ route('page.chapter', [$manga->slug, $chapter->id]) }}" class="list-group-item list-group-item-action">
{{ $chapter->title }}
</a>
@empty
<p class="text-danger">No Chapter Yet!</p>
@endforelse
</ul>
</div>
@endsection
@section('footer')
@include('partials.footer')
<x-footer />
@endsection

View File

@ -1,29 +1,30 @@
@extends('layouts.app')
@section('content')
<form method="POST" action="{{ route('manga.store') }}" enctype="multipart/form-data">
@csrf
<div class="mb-3">
<label for="">Manga Title</label>
<input type="text" name="title" class="form-control">
@error('title')
<p class="text-danger small">{{ $message }}</p>
@enderror
</div>
<div class="mb-3">
<label for="">Manga Cover</label>
<input type="file" name="cover" id="" class="form-control">
</div>
<div class="mb-3">
<label for="">Manga Summary</label>
<textarea name="summary" id="" cols="30" rows="6" class="form-control p-3"
placeholder="Write A Summary">
<x-card-card-body>
<form method="POST" action="{{ route('manga.store') }}" enctype="multipart/form-data">
@csrf
<div class="mb-3">
<label for="">Manga Title</label>
<input type="text" name="title" class="form-control">
@error('title')
<p class="text-danger small">{{ $message }}</p>
@enderror
</div>
<div class="mb-3">
<label for="">Manga Cover</label>
<input type="file" name="cover" id="" class="form-control">
</div>
<div class="mb-3">
<label for="">Manga Summary</label>
<textarea name="summary" id="" cols="30" rows="6" class="form-control p-3"
placeholder="Write A Summary">
</textarea>
@error('summary')
<p class="text-danger small">{{ $message }}</p>
@enderror
</div>
<button type="submit" class="btn btn-outline-dark">Create</button>
</form>
</textarea>
@error('summary')
<p class="text-danger small">{{ $message }}</p>
@enderror
</div>
<button type="submit" class="btn btn-outline-dark">Create</button>
</form>
</x-card-card-body>
@endsection

View File

@ -9,7 +9,7 @@
<hr>
<p class="f">Cover Image :</p>
<div class="text-center mb-4">
<img class="w-25" src="{{ $manga->cover ? asset( $manga->cover) : '' }}" alt="">
<img class="w-25" src="{{ asset('storage/'.$manga->cover) }}" alt="">
</div>
<hr>
<p class="mb-0">Summary :</p>
@ -18,10 +18,10 @@
<div class="d-flex justify-content-between">
<p>Total Chapter : <span class="text-primary fw-semibold">{{$manga->chapters->count()}} chapters</span> </p>
<div>
<a href="" class="btn btn-outline-dark btn-sm">Go Manage Chapters <i class="bi bi-arrow-right-circle-fill"></i> </a>
<a href="{{route('chapters.manage', $manga->slug)}}" class="btn btn-outline-dark btn-sm">Go Manage Chapters <i class="bi bi-arrow-right-circle-fill"></i> </a>
</div>
</div>
<hr>
</div>
</div>

View File

@ -1,68 +1,7 @@
@extends('layouts.app')
@section('content')
<div class="card">
<div class="card-body">
<h5>Manga List</h5>
<hr>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col" style="min-width: 20%">Title</th>
<th>Author</th>
<th scope="col">Total Chapters</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
@forelse ($mangas as $manga)
<tr>
<th scope="row"> {{ $manga->id }} </th>
<td>
<p class="mb-0">{{ $manga->title }}</p>
<span class="small text-black-50">{{ $manga->excerpt }}</span>
</td>
<td>
{{ $manga->user->name }}
</td>
<td class="text-center">
{{$manga->chapters->count()}}
</td>
<td>
<div class="btn-group">
<a href="{{route('manga.show', $manga->slug)}}" class="btn btn-outline-dark"><i class="bi bi-exclamation-diamond"></i></a>
<a href="{{ route('manga.edit', $manga->id) }}" class="btn btn-outline-dark"
title="edit">
<i class="bi bi-pencil-square"></i>
</a>
<button class="btn btn-outline-dark" form="deleteForm{{ $manga->id }}"
title="delete" onclick="return confirm('Are sure to delete?')">
<i class="bi bi-trash3"></i>
</button>
</div>
<form method="post" id="deleteForm{{ $manga->id }}"
action="{{ route('manga.destroy', $manga->id) }}" class="d-inline-block">
@csrf
@method('delete')
</form>
</td>
</tr>
@empty
@endforelse
</tbody>
</table>
</div>
<div class="">
{{ $mangas->links() }}
</div>
</div>
</div>
<x-card-card-body >
<x-manga-list :mangas="$mangas" />
</x-card-card-body>
@endsection

View File

@ -0,0 +1,8 @@
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item text-decoration-none"><a href="{{ route('page.index') }}">Home</a></li>
<li class="breadcrumb-item text-decoration-none"><a href="{{ route('page.manga', $manga->slug) }}">
{{ $manga->title }} </a></li>
<li class="breadcrumb-item active" aria-current="page">Chapter {{ $chapter->chapter_no }} </li>
</ol>
</nav>

View File

@ -0,0 +1,4 @@
<div>
<a href="" class="btn btn-dark btn-small">Previous</a>
<a href="" class="btn btn-dark btn-small">Next</a>
</div>

View File

@ -0,0 +1,8 @@
<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>
@endforeach
</select>
</div>

View File

@ -1,25 +1,26 @@
<h4 class="fw-semibold">Manga Hot</h4>
<div class="row">
@foreach ($hotMangas as $hotManga)
@forelse (App\Models\Manga::latest('id')->limit(3)->get() as $hotManga)
<div class="col-12 mt-3">
<div class="d-flex border-0">
<div>
<a href="{{ route('page.manga', $hotManga->slug) }}"><img src="{{ asset($hotManga->cover) }}" alt="img" style="width: 80px"></a>
<a href="{{ route('page.manga', $hotManga->slug) }}">
<img src="{{ asset( 'storage/'.$hotManga->cover) }}"
alt="img" style="max-width: 80px">
</a>
</div>
<div class="ms-2">
<p class="fw-semibold mb-1"> {{ $hotManga->title }} </p>
@foreach ($hotManga->chapters()->latest('id')->limit(2)->get() as $hotChap)
<div class="d-flex justify-content-between flex-wrap mb-2">
<a href="{{route('page.chapter',[$hotManga->slug, $hotChap->id])}}"
class="text-decoration-none text-white small bg-secondary rounded-pill px-1">
{{ $hotChap->title }}
</a>
<span class="small"> {{$hotChap->created_at->diffForHumans()}} </span>
</div>
@endforeach
@foreach ($hotManga->chapters()->latest('id')->limit(2)->get() as $hotChap)
<x-latest-chapter :manga="$hotManga" :chapter="$hotChap" />
@endforeach
</div>
</div>
</div>
@endforeach
@empty
<p class="text-danger small">No Hot Manga Yet</p>
@endforelse
</div>

View File

@ -0,0 +1,6 @@
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item text-decoration-none"><a href="{{ route('page.index') }}">Home</a></li>
<li class="breadcrumb-item active" aria-current="page"> {{ $manga->title }} </li>
</ol>
</nav>

View File

@ -1,11 +1,19 @@
<ul class="list-group">
<h5>Manga</h5>
<a href="{{route('manga.index')}}" class="list-group-item list-group-item-action"><i class="bi bi-book"></i> Manga List </a>
<a href="{{route('manga.create')}}" class="list-group-item list-group-item-action"><i class="bi bi-plus-circle-fill"></i> Create Manga</a>
<a href="{{ route('manga.index') }}" class="list-group-item list-group-item-action"><i class="bi bi-book"></i> Manga
List </a>
<a href="{{ route('manga.create') }}" class="list-group-item list-group-item-action"><i
class="bi bi-plus-circle-fill"></i> Create Manga</a>
<h5 class="mt-4">Chapters</h5>
<a href=" {{route('chapter.index')}} " class="list-group-item list-group-item-action"><i class="bi bi-book"></i> Chapter List </a>
<a href="{{route('chapter.create')}}" class="list-group-item list-group-item-action"><i class="bi bi-plus-circle-fill"></i> Create Chapter</a>
<a href=" {{ route('chapter.index') }} " class="list-group-item list-group-item-action"><i class="bi bi-book"></i>
Chapter List </a>
<a href="{{ route('chapter.create') }}" class="list-group-item list-group-item-action"><i
class="bi bi-plus-circle-fill"></i> Create Chapter</a>
@can('admin-only')
<h5 class="mt-4">Users</h5>
<a href="{{ route('users.list') }}" class="list-group-item list-group-item-action"> <i class="bi bi-people"></i>
Users List</a>
@endcan
</ul>

View File

@ -0,0 +1,43 @@
@extends('layouts.app')
@section('content')
<x-card-card-body>
<h5>User List</h5>
<hr>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col" style="min-width: 20%">Name</th>
<th>Role</th>
<th scope="col">Manga Count(created) </th>
<th scope="col">Created_at</th>
</tr>
</thead>
<tbody>
@forelse ($users as $key => $user)
<tr>
<td> {{ $key }} </td>
<td> {{ $user->name }} </td>
<td> {{ $user->role }} </td>
<td> {{ $user->mangas->count() }} </td>
<td>
<p class="mb-0 small"> <i class="bi bi-clock-history"></i>
{{ $user->created_at->format('H:i a') }} </p>
<p class="mb-0 small"> <i class="bi bi-calendar-check"></i>
{{ $user->created_at->format('d-m-Y') }} </p>
</td>
</tr>
@empty
<p class="text-danger">No User Yet</p>
@endforelse
</tbody>
</table>
</div>
<div>
{{$users->links()}}
</div>
</x-card-card-body>
@endsection

View File

@ -4,6 +4,7 @@ use App\Http\Controllers\ChapterController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\MangaController;
use App\Http\Controllers\PageController;
use App\Http\Controllers\UserController;
use App\Models\Chapter;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
@ -19,8 +20,8 @@ use Illuminate\Support\Facades\Route;
|
*/
Route::controller(PageController::class)->group(function() {
Route::get('/','index')->name('page.index');
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')->name('page.chapter');
});
@ -29,7 +30,12 @@ Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::resource('manga', MangaController::class)->middleware('auth');
Route::middleware(['auth', 'admin.access'])->group(function () {
Route::resource('manga', MangaController::class);
Route::resource('chapter', ChapterController::class)->middleware('auth');
Route::get('/chapters/manage/{manga:slug}', [ChapterController::class, 'manage'])->name('chapters.manage')->middleware('auth');
Route::resource('chapter', ChapterController::class);
Route::get('/chapters/manage/{manga:slug}', [ChapterController::class, 'manage'])->name('chapters.manage');
Route::get('/users-list', [UserController::class, 'index'])->name('users.list')->middleware('can:admin-only');
});