forked from schoolofnetcom/iniciando-laravel-8
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Formatação da URL gerada na paginação
- Loading branch information
1 parent
133d0aa
commit 334d2e1
Showing
5 changed files
with
30 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Models\Traits; | ||
|
||
use Illuminate\Pagination\Paginator; | ||
|
||
Trait PaginateTrait | ||
{ | ||
public static function scopePaginateUri($query, $items, $page) | ||
{ | ||
$action = app('request')->route()->getActionName(); | ||
$parameters = app('request')->route()->parameters(); | ||
$parameters['page'] = '##'; // ## == %23%23 | ||
$current_url = action($action, $parameters); | ||
$current_url = preg_replace('/[\?\=]/', '/', $current_url); | ||
Paginator::currentPageResolver(function () use ($page) { | ||
return $page; | ||
}); | ||
$paginate = $query->paginate($items); | ||
$links = preg_replace('@href="(.*/?page=(\d+))"@U', 'href="' . str_replace('%23%23', '$2', $current_url) . '"', $paginate->render()); | ||
$paginate->linksUri = $links; | ||
return $paginate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
334d2e1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For append queries to links in pagination
334d2e1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, @sta6
How can I use this attribute?
Can you show me an exemplo, please?
Thank you for your contribution.