回答編集履歴
3
引用の追加
test
CHANGED
@@ -47,3 +47,337 @@
|
|
47
47
|
@endif
|
48
48
|
|
49
49
|
```
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
###追記(Laravel5.0)※未検証
|
54
|
+
|
55
|
+
[Laravel 5 で Paginator->render() する時、自前のテンプレートを用いる方法
|
56
|
+
|
57
|
+
](http://qiita.com/hokutoasari/items/65e5d2f7a6a562649f23)
|
58
|
+
|
59
|
+
```php
|
60
|
+
|
61
|
+
<?php namespace App\Presenters;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
use Illuminate\Pagination\BootstrapThreePresenter;
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
class CustomPresenter extends BootstrapThreePresenter {
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
public function render()
|
74
|
+
|
75
|
+
{
|
76
|
+
|
77
|
+
if( ! $this->hasPages())
|
78
|
+
|
79
|
+
return '';
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
return sprintf(
|
84
|
+
|
85
|
+
'<div class="pagination">%s %s %s</div>',
|
86
|
+
|
87
|
+
$this->getPreviousButton(),
|
88
|
+
|
89
|
+
$this->getLinks(),
|
90
|
+
|
91
|
+
$this->getNextButton()
|
92
|
+
|
93
|
+
);
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
/**
|
100
|
+
|
101
|
+
* Get HTML wrapper for an available page link.
|
102
|
+
|
103
|
+
*
|
104
|
+
|
105
|
+
* @param string $url
|
106
|
+
|
107
|
+
* @param int $page
|
108
|
+
|
109
|
+
* @param string|null $rel
|
110
|
+
|
111
|
+
* @return string
|
112
|
+
|
113
|
+
*/
|
114
|
+
|
115
|
+
protected function getAvailablePageWrapper($url, $page, $rel = null)
|
116
|
+
|
117
|
+
{
|
118
|
+
|
119
|
+
$rel = is_null($rel) ? '' : ' rel="'.$rel.'"';
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
return '<a href="'.htmlentities($url).'"'.$rel.'>'.$page.'</a>';
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
/**
|
130
|
+
|
131
|
+
* Get HTML wrapper for disabled text.
|
132
|
+
|
133
|
+
*
|
134
|
+
|
135
|
+
* @param string $text
|
136
|
+
|
137
|
+
* @return string
|
138
|
+
|
139
|
+
*/
|
140
|
+
|
141
|
+
protected function getDisabledTextWrapper($text)
|
142
|
+
|
143
|
+
{
|
144
|
+
|
145
|
+
return '<span>'.$text.'</span>';
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
/**
|
152
|
+
|
153
|
+
* Get HTML wrapper for active text.
|
154
|
+
|
155
|
+
*
|
156
|
+
|
157
|
+
* @param string $text
|
158
|
+
|
159
|
+
* @return string
|
160
|
+
|
161
|
+
*/
|
162
|
+
|
163
|
+
protected function getActivePageWrapper($text)
|
164
|
+
|
165
|
+
{
|
166
|
+
|
167
|
+
return '<span>['.$text.']</span>';
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
```
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
他にはこれ等も参考になると思います。
|
178
|
+
|
179
|
+
[Laravel5のページナビをカスタマイズする](https://blog.e2info.co.jp/2016/04/16/laravel5_pagination/)
|
180
|
+
|
181
|
+
```php
|
182
|
+
|
183
|
+
<?php
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
namespace App\Http\Pagination;
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
use Illuminate\Support\HtmlString;
|
192
|
+
|
193
|
+
use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
|
194
|
+
|
195
|
+
use Illuminate\Contracts\Pagination\Presenter as PresenterContract;
|
196
|
+
|
197
|
+
use App\Http\Pagination\UrlWindowPresenterTrait;
|
198
|
+
|
199
|
+
use Illuminate\Pagination\BootstrapThreeNextPreviousButtonRendererTrait;
|
200
|
+
|
201
|
+
use Illuminate\Pagination\UrlWindow;
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
class FrontPaginationPresenter implements PresenterContract
|
206
|
+
|
207
|
+
{
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
use BootstrapThreeNextPreviousButtonRendererTrait,
|
212
|
+
|
213
|
+
UrlWindowPresenterTrait;
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
protected $paginator;
|
218
|
+
|
219
|
+
protected $window;
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
public function __construct(PaginatorContract $paginator, UrlWindow $window = null)
|
224
|
+
|
225
|
+
{
|
226
|
+
|
227
|
+
$this->paginator = $paginator;
|
228
|
+
|
229
|
+
$this->window = is_null($window) ? UrlWindow::make($paginator) : $window->get();
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
public function hasPages()
|
236
|
+
|
237
|
+
{
|
238
|
+
|
239
|
+
return $this->paginator->hasPages();
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
// レンダリング
|
246
|
+
|
247
|
+
public function render()
|
248
|
+
|
249
|
+
{
|
250
|
+
|
251
|
+
if ($this->hasPages()) {
|
252
|
+
|
253
|
+
return new HtmlString(sprintf(
|
254
|
+
|
255
|
+
'<ul class="pagination">%s %s %s %s %s</ul>', $this->getFirstButton(), $this->getPreviousButton(), $this->getLinks(), $this->getNextButton(), $this->getLastButton()
|
256
|
+
|
257
|
+
));
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
return '';
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
// 通常のタグ
|
270
|
+
|
271
|
+
protected function getAvailablePageWrapper($url, $page, $rel = null)
|
272
|
+
|
273
|
+
{
|
274
|
+
|
275
|
+
$rel = is_null($rel) ? '' : ' rel="' . $rel . '"';
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
return '<li><a href="' . htmlentities($url) . '"' . $rel . '>' . $page . '</a></li>';
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
// リンク無効な文字列のタグ
|
286
|
+
|
287
|
+
protected function getDisabledTextWrapper($text)
|
288
|
+
|
289
|
+
{
|
290
|
+
|
291
|
+
return '<li class="disabled"><span>' . $text . '</span></li>';
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
// 現在のページ
|
298
|
+
|
299
|
+
protected function getActivePageWrapper($text)
|
300
|
+
|
301
|
+
{
|
302
|
+
|
303
|
+
return '<li class="active"><span>' . $text . '</span></li>';
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
protected function getDots()
|
310
|
+
|
311
|
+
{
|
312
|
+
|
313
|
+
return $this->getDisabledTextWrapper('...');
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
```
|
320
|
+
|
321
|
+
```php
|
322
|
+
|
323
|
+
<?php
|
324
|
+
|
325
|
+
namespace App\Http\Pagination;
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
trait UrlWindowPresenterTrait
|
330
|
+
|
331
|
+
{
|
332
|
+
|
333
|
+
use \Illuminate\Pagination\UrlWindowPresenterTrait;
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
protected function getFirstButton($text = 'First')
|
338
|
+
|
339
|
+
{
|
340
|
+
|
341
|
+
if ($this->paginator->currentPage() <= 1) {
|
342
|
+
|
343
|
+
return $this->getDisabledTextWrapper($text);
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
return $this->getPageLinkWrapper(
|
350
|
+
|
351
|
+
$this->paginator->url(1), $text, 'first'
|
352
|
+
|
353
|
+
);
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
protected function getLastButton($text = 'Last')
|
360
|
+
|
361
|
+
{
|
362
|
+
|
363
|
+
if (!$this->paginator->hasMorePages()) {
|
364
|
+
|
365
|
+
return $this->getDisabledTextWrapper($text);
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
return $this->getPageLinkWrapper(
|
372
|
+
|
373
|
+
$this->paginator->url($this->lastPage()), $text, 'last'
|
374
|
+
|
375
|
+
);
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
}
|
380
|
+
|
381
|
+
```
|
382
|
+
|
383
|
+
|
2
simplepaginateに修正
test
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
①```php artisan vendor:publish```で上書用のviewを自動生成
|
4
4
|
|
5
|
-
②\views\vendor\pagination\default.blade.phpが下記の通り生成されるので
|
5
|
+
②\views\vendor\pagination\simple-default.blade.phpが下記の通り生成されるので表示文字を変更
|
6
6
|
|
7
|
-
(
|
7
|
+
(表示したい文字に変更)
|
8
8
|
|
9
9
|
```html
|
10
10
|
|
@@ -22,47 +22,9 @@
|
|
22
22
|
|
23
23
|
<!--<li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">«</a></li>-->
|
24
24
|
|
25
|
-
<li><a href="{{ $paginator->previousPageUrl() }}">前へ</a></li>
|
25
|
+
<li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">前へ</a></li>
|
26
26
|
|
27
27
|
@endif
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
{{-- Pagination Elements --}}
|
32
|
-
|
33
|
-
@foreach ($elements as $element)
|
34
|
-
|
35
|
-
{{-- "Three Dots" Separator --}}
|
36
|
-
|
37
|
-
@if (is_string($element))
|
38
|
-
|
39
|
-
<li class="disabled"><span>{{ $element }}</span></li>
|
40
|
-
|
41
|
-
@endif
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
{{-- Array Of Links --}}
|
46
|
-
|
47
|
-
@if (is_array($element))
|
48
|
-
|
49
|
-
@foreach ($element as $page => $url)
|
50
|
-
|
51
|
-
@if ($page == $paginator->currentPage())
|
52
|
-
|
53
|
-
<li class="active"><span>{{ $page }}</span></li>
|
54
|
-
|
55
|
-
@else
|
56
|
-
|
57
|
-
<li><a href="{{ $url }}">{{ $page }}</a></li>
|
58
|
-
|
59
|
-
@endif
|
60
|
-
|
61
|
-
@endforeach
|
62
|
-
|
63
|
-
@endif
|
64
|
-
|
65
|
-
@endforeach
|
66
28
|
|
67
29
|
|
68
30
|
|
@@ -72,7 +34,7 @@
|
|
72
34
|
|
73
35
|
<!--<li><a href="{{ $paginator->nextPageUrl() }}" rel="next">»</a></li>-->
|
74
36
|
|
75
|
-
<li><a href="{{ $paginator->nextPageUrl() }}">次へ</a></li>
|
37
|
+
<li><a href="{{ $paginator->nextPageUrl() }}" rel="next">次へ</a></li>
|
76
38
|
|
77
39
|
@else
|
78
40
|
|
@@ -84,6 +46,4 @@
|
|
84
46
|
|
85
47
|
@endif
|
86
48
|
|
87
|
-
|
88
|
-
|
89
49
|
```
|
1
書式の改善
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
(rel属性を削除して表示したい文字に変更)
|
8
8
|
|
9
|
-
```
|
9
|
+
```html
|
10
10
|
|
11
11
|
@if ($paginator->hasPages())
|
12
12
|
|