質問編集履歴

2

変更

2023/08/18 13:51

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -3,151 +3,3 @@
3
3
  laravel9.8.1で掲示板を作成しています。ペジネーションの表示を番号で表示したいのですが、上手くいきません。
4
4
  simplePaginateメソッドではなく、paginateメソッドを使っているものの「« PreviousNext »」表示になってしまいます。
5
5
 
6
-
7
-
8
- ###
9
-
10
- ```index.blade.php
11
- @extends('layouts.base')
12
-
13
- @section('content')
14
-
15
- @include("parts.thread_entry_form")
16
- <link href="/css/app.css" rel="stylesheet">
17
-
18
- <h2>記事一覧</h2>
19
- {{--ソートボタン--}}
20
- <div>
21
- <div class="new">
22
- <a href="{{url('/', ['sort' => 'new'])}}">新着順</a>
23
- </div>
24
-
25
- <div class="">
26
- <a href="{{url('/', ['sort' => 'popular'])}}">人気順</a>
27
- </div>
28
- </div>
29
- {{--一覧--}}
30
- <div class="entry">
31
- <ul>
32
- @foreach($item_list as $item)
33
- <li>
34
- <a href="{{ route('post.show', ['id'=>$item->id])}}">
35
- <div class="info">
36
- {{$item->created_at}}
37
- </div>
38
- <p>{{$item->title}}</p>
39
- <p>{{$item->posts_count}}</p>
40
- </a>
41
- </li>
42
- @endforeach
43
- </ul>
44
- </div>
45
- <hr>
46
- {{ $item_list->links() }}
47
- @if(count($item_list) < 1)
48
- <p>投稿がありません</p>
49
- @endif
50
- @endsection
51
- ```
52
-
53
- ```ThreadController.php
54
- <?php
55
-
56
- namespace App\Http\Controllers;
57
-
58
- use Illuminate\Http\Request;
59
- use App\Models\Post;
60
- use App\Models\Thread;
61
- use Carbon\Carbon;
62
- use Illuminate\Pagination\Paginator;
63
-
64
- class ThreadController extends Controller
65
- {
66
- //一覧表示
67
- function index($sort= 'new'){
68
- //ソート
69
- $flag = $sort;
70
- $order = 'asc';
71
- if($flag == 'new'){
72
- $flag = 'created_at';
73
- $order = 'desc';
74
-
75
- $item_list = Thread::withCount('posts')->orderBy($flag, $order)->paginate(3);
76
- };
77
- if($flag == 'popular'){
78
- $flag = 'posts_count';
79
- $order = 'desc';
80
-
81
- //日付作成今日作成されたデータをを取り出す
82
- $oneday = Carbon::today()->subDay(1);
83
- $item_list = Thread::withCount('posts')->orderBy($flag, $order)->whereDate('created_at', '>=', $oneday)->paginate(3);
84
-
85
- };
86
-
87
-
88
- return view("index", compact('item_list'));
89
-
90
- }
91
-
92
- //投稿処理
93
- function create(Request $request){
94
- $input = $request->only('name', 'title', 'body', 'flag');
95
-
96
- $entryThread = new Thread();
97
- $entryThread->title = $input["title"];
98
- $entryThread->save();
99
-
100
- $entryPost = new Post();
101
- $entryPost->name = $input["name"];
102
- $entryPost->body = $input["body"];
103
- $entryPost->thread_id = Thread::max('id');
104
- $entryPost->user_id = $request->ip();
105
- $entryPost->save();
106
-
107
- return redirect('/');
108
- }
109
-
110
- //スレッド詳細
111
- function show($id){
112
- $thread = Thread::find($id);
113
-
114
- return view('post', ["thread" => $thread]);
115
- }
116
- }
117
-
118
- ```
119
- ### 追記
120
- AppServiceProvider.phpを確認してみましたが、恐らく直接は何も書き込んでいないと思います。
121
-
122
- ```AppServiceProvider.php
123
- <?php
124
-
125
- namespace App\Providers;
126
-
127
- use Illuminate\Support\ServiceProvider;
128
-
129
- class AppServiceProvider extends ServiceProvider
130
- {
131
- /**
132
- * Register any application services.
133
- *
134
- * @return void
135
- */
136
- public function register()
137
- {
138
- //
139
- }
140
-
141
- /**
142
- * Bootstrap any application services.
143
- *
144
- * @return void
145
- */
146
- public function boot()
147
- {
148
- //
149
- }
150
- }
151
-
152
- ```
153
-

1

AppServiceProviderコードの追加

2022/04/20 09:31

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -116,5 +116,38 @@
116
116
  }
117
117
 
118
118
  ```
119
+ ### 追記
120
+ AppServiceProvider.phpを確認してみましたが、恐らく直接は何も書き込んでいないと思います。
119
121
 
122
+ ```AppServiceProvider.php
123
+ <?php
120
124
 
125
+ namespace App\Providers;
126
+
127
+ use Illuminate\Support\ServiceProvider;
128
+
129
+ class AppServiceProvider extends ServiceProvider
130
+ {
131
+ /**
132
+ * Register any application services.
133
+ *
134
+ * @return void
135
+ */
136
+ public function register()
137
+ {
138
+ //
139
+ }
140
+
141
+ /**
142
+ * Bootstrap any application services.
143
+ *
144
+ * @return void
145
+ */
146
+ public function boot()
147
+ {
148
+ //
149
+ }
150
+ }
151
+
152
+ ```
153
+