Skip to content

Commit

Permalink
Creted_10-1~10-3
Browse files Browse the repository at this point in the history
  • Loading branch information
R.Nishi committed Nov 4, 2024
1 parent c23c957 commit 88bfc63
Show file tree
Hide file tree
Showing 14 changed files with 472 additions and 12 deletions.
20 changes: 11 additions & 9 deletions example-app/app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Http\Controllers;

use App\Models\post;
use App\Models\Post;
use Illuminate\Http\Request;

class PostController extends Controller
Expand All @@ -12,8 +12,9 @@ class PostController extends Controller
*/
public function index()
{
$post=Post::all();
return view('post.index',compact('posts'));
$posts=Post::paginate(10);
// $post=Post::all();
return view('post.index', compact('posts'));
}

/**
Expand All @@ -30,10 +31,11 @@ public function create()
public function store(Request $request)
{
$validated = $request->validate([
'title' =>'required|max:20',
'body' =>'required|max:400',
'title' => 'required|max:20',
'body' => 'required|max:400',
]);
$validated['user_id'] = auth()->id();

$post = Post::create($validated);

$request->session()->flash('message', '保存しました');
Expand All @@ -43,23 +45,23 @@ public function store(Request $request)
/**
* Display the specified resource.
*/
public function show(post $post)
public function show(Post $post)
{
return view('post.show',compact('post'));
}

/**
* Show the form for editing the specified resource.
*/
public function edit(post $post)
public function edit(Post $post)
{
return view('post.edit',compact('post'));
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, post $post)
public function update(Request $request, Post $post)
{
$validated = $request->validate([
'title' =>'required|max:20',
Expand All @@ -75,7 +77,7 @@ public function update(Request $request, post $post)
/**
* Remove the specified resource from storage.
*/
public function destroy(Request $request,post $post)
public function destroy(Request $request,Post $post)
{
$post->delete;
$request->session()->flash('message', '削除しました');
Expand Down
25 changes: 25 additions & 0 deletions example-app/app/View/Components/Message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\View\Components;

use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class Message extends Component
{
public $message;
public function __construct($message)
{
$this->message = $message;
}


/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.message');
}
}
2 changes: 1 addition & 1 deletion example-app/database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public function run(): void
// 'name' => 'Test User',
// 'email' => '[email protected]',
// ]);
\App\Models\Post::factory(3)->create();
\App\Models\Post::factory(10)->create();
}
}
7 changes: 7 additions & 0 deletions example-app/resources/views/components/message.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div>
@if ($message)
<div class="p-4 m-2 rounded bg-green-100">
{{ $message }}
</div>
@endif
</div>
8 changes: 6 additions & 2 deletions example-app/resources/views/post/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
</h2>
</x-slot>
<div class="mx-auto px-6">
@if (session('message'))
{{-- @if (session('message'))
<div class="text-red-600 font-bold">
{{ session('message') }}
</div>
@endif
@endif --}}
<x-message :message="session('message')" />
@foreach ($posts as $post)
<div class="mt-4 p-8 bg-white w-full rounded-2xl">
<h1 class="p-4text-lg font-semibold">
Expand All @@ -30,5 +31,8 @@ class="text-blue-600">
</div>
</div>
@endforeach
<div class="mb-4">
{{ $posts->links() }}
</div>
</div>
</x-app-layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@if ($paginator->hasPages())
<nav>
<ul class="pagination">
{{-- Previous Page Link --}}
@if ($paginator->onFirstPage())
<li class="page-item disabled" aria-disabled="true" aria-label="@lang('pagination.previous')">
<span class="page-link" aria-hidden="true">&lsaquo;</span>
</li>
@else
<li class="page-item">
<a class="page-link" href="{{ $paginator->previousPageUrl() }}" rel="prev" aria-label="@lang('pagination.previous')">&lsaquo;</a>
</li>
@endif

{{-- Pagination Elements --}}
@foreach ($elements as $element)
{{-- "Three Dots" Separator --}}
@if (is_string($element))
<li class="page-item disabled" aria-disabled="true"><span class="page-link">{{ $element }}</span></li>
@endif

{{-- Array Of Links --}}
@if (is_array($element))
@foreach ($element as $page => $url)
@if ($page == $paginator->currentPage())
<li class="page-item active" aria-current="page"><span class="page-link">{{ $page }}</span></li>
@else
<li class="page-item"><a class="page-link" href="{{ $url }}">{{ $page }}</a></li>
@endif
@endforeach
@endif
@endforeach

{{-- Next Page Link --}}
@if ($paginator->hasMorePages())
<li class="page-item">
<a class="page-link" href="{{ $paginator->nextPageUrl() }}" rel="next" aria-label="@lang('pagination.next')">&rsaquo;</a>
</li>
@else
<li class="page-item disabled" aria-disabled="true" aria-label="@lang('pagination.next')">
<span class="page-link" aria-hidden="true">&rsaquo;</span>
</li>
@endif
</ul>
</nav>
@endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
@if ($paginator->hasPages())
<nav class="d-flex justify-items-center justify-content-between">
<div class="d-flex justify-content-between flex-fill d-sm-none">
<ul class="pagination">
{{-- Previous Page Link --}}
@if ($paginator->onFirstPage())
<li class="page-item disabled" aria-disabled="true">
<span class="page-link">@lang('pagination.previous')</span>
</li>
@else
<li class="page-item">
<a class="page-link" href="{{ $paginator->previousPageUrl() }}" rel="prev">@lang('pagination.previous')</a>
</li>
@endif

{{-- Next Page Link --}}
@if ($paginator->hasMorePages())
<li class="page-item">
<a class="page-link" href="{{ $paginator->nextPageUrl() }}" rel="next">@lang('pagination.next')</a>
</li>
@else
<li class="page-item disabled" aria-disabled="true">
<span class="page-link">@lang('pagination.next')</span>
</li>
@endif
</ul>
</div>

<div class="d-none flex-sm-fill d-sm-flex align-items-sm-center justify-content-sm-between">
<div>
<p class="small text-muted">
{!! __('Showing') !!}
<span class="fw-semibold">{{ $paginator->firstItem() }}</span>
{!! __('to') !!}
<span class="fw-semibold">{{ $paginator->lastItem() }}</span>
{!! __('of') !!}
<span class="fw-semibold">{{ $paginator->total() }}</span>
{!! __('results') !!}
</p>
</div>

<div>
<ul class="pagination">
{{-- Previous Page Link --}}
@if ($paginator->onFirstPage())
<li class="page-item disabled" aria-disabled="true" aria-label="@lang('pagination.previous')">
<span class="page-link" aria-hidden="true">&lsaquo;</span>
</li>
@else
<li class="page-item">
<a class="page-link" href="{{ $paginator->previousPageUrl() }}" rel="prev" aria-label="@lang('pagination.previous')">&lsaquo;</a>
</li>
@endif

{{-- Pagination Elements --}}
@foreach ($elements as $element)
{{-- "Three Dots" Separator --}}
@if (is_string($element))
<li class="page-item disabled" aria-disabled="true"><span class="page-link">{{ $element }}</span></li>
@endif

{{-- Array Of Links --}}
@if (is_array($element))
@foreach ($element as $page => $url)
@if ($page == $paginator->currentPage())
<li class="page-item active" aria-current="page"><span class="page-link">{{ $page }}</span></li>
@else
<li class="page-item"><a class="page-link" href="{{ $url }}">{{ $page }}</a></li>
@endif
@endforeach
@endif
@endforeach

{{-- Next Page Link --}}
@if ($paginator->hasMorePages())
<li class="page-item">
<a class="page-link" href="{{ $paginator->nextPageUrl() }}" rel="next" aria-label="@lang('pagination.next')">&rsaquo;</a>
</li>
@else
<li class="page-item disabled" aria-disabled="true" aria-label="@lang('pagination.next')">
<span class="page-link" aria-hidden="true">&rsaquo;</span>
</li>
@endif
</ul>
</div>
</div>
</nav>
@endif
46 changes: 46 additions & 0 deletions example-app/resources/views/vendor/pagination/default.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@if ($paginator->hasPages())
<nav>
<ul class="pagination">
{{-- Previous Page Link --}}
@if ($paginator->onFirstPage())
<li class="disabled" aria-disabled="true" aria-label="@lang('pagination.previous')">
<span aria-hidden="true">&lsaquo;</span>
</li>
@else
<li>
<a href="{{ $paginator->previousPageUrl() }}" rel="prev" aria-label="@lang('pagination.previous')">&lsaquo;</a>
</li>
@endif

{{-- Pagination Elements --}}
@foreach ($elements as $element)
{{-- "Three Dots" Separator --}}
@if (is_string($element))
<li class="disabled" aria-disabled="true"><span>{{ $element }}</span></li>
@endif

{{-- Array Of Links --}}
@if (is_array($element))
@foreach ($element as $page => $url)
@if ($page == $paginator->currentPage())
<li class="active" aria-current="page"><span>{{ $page }}</span></li>
@else
<li><a href="{{ $url }}">{{ $page }}</a></li>
@endif
@endforeach
@endif
@endforeach

{{-- Next Page Link --}}
@if ($paginator->hasMorePages())
<li>
<a href="{{ $paginator->nextPageUrl() }}" rel="next" aria-label="@lang('pagination.next')">&rsaquo;</a>
</li>
@else
<li class="disabled" aria-disabled="true" aria-label="@lang('pagination.next')">
<span aria-hidden="true">&rsaquo;</span>
</li>
@endif
</ul>
</nav>
@endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@if ($paginator->hasPages())
<div class="ui pagination menu" role="navigation">
{{-- Previous Page Link --}}
@if ($paginator->onFirstPage())
<a class="icon item disabled" aria-disabled="true" aria-label="@lang('pagination.previous')"> <i class="left chevron icon"></i> </a>
@else
<a class="icon item" href="{{ $paginator->previousPageUrl() }}" rel="prev" aria-label="@lang('pagination.previous')"> <i class="left chevron icon"></i> </a>
@endif

{{-- Pagination Elements --}}
@foreach ($elements as $element)
{{-- "Three Dots" Separator --}}
@if (is_string($element))
<a class="icon item disabled" aria-disabled="true">{{ $element }}</a>
@endif

{{-- Array Of Links --}}
@if (is_array($element))
@foreach ($element as $page => $url)
@if ($page == $paginator->currentPage())
<a class="item active" href="{{ $url }}" aria-current="page">{{ $page }}</a>
@else
<a class="item" href="{{ $url }}">{{ $page }}</a>
@endif
@endforeach
@endif
@endforeach

{{-- Next Page Link --}}
@if ($paginator->hasMorePages())
<a class="icon item" href="{{ $paginator->nextPageUrl() }}" rel="next" aria-label="@lang('pagination.next')"> <i class="right chevron icon"></i> </a>
@else
<a class="icon item disabled" aria-disabled="true" aria-label="@lang('pagination.next')"> <i class="right chevron icon"></i> </a>
@endif
</div>
@endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@if ($paginator->hasPages())
<nav>
<ul class="pagination">
{{-- Previous Page Link --}}
@if ($paginator->onFirstPage())
<li class="page-item disabled" aria-disabled="true">
<span class="page-link">@lang('pagination.previous')</span>
</li>
@else
<li class="page-item">
<a class="page-link" href="{{ $paginator->previousPageUrl() }}" rel="prev">@lang('pagination.previous')</a>
</li>
@endif

{{-- Next Page Link --}}
@if ($paginator->hasMorePages())
<li class="page-item">
<a class="page-link" href="{{ $paginator->nextPageUrl() }}" rel="next">@lang('pagination.next')</a>
</li>
@else
<li class="page-item disabled" aria-disabled="true">
<span class="page-link">@lang('pagination.next')</span>
</li>
@endif
</ul>
</nav>
@endif
Loading

0 comments on commit 88bfc63

Please sign in to comment.