-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'filamentphp:main' into main
- Loading branch information
Showing
416 changed files
with
25,836 additions
and
14,460 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Author; | ||
|
||
class AuthorController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
return Author::paginate(); | ||
} | ||
|
||
public function show(Author $author) | ||
{ | ||
return $author->append('stars_count'); | ||
} | ||
} |
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
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
2 changes: 1 addition & 1 deletion
2
content/articles/leandrocfe-how-to-refresh-widgets-when-table-actions-are-fired.md
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
2 changes: 1 addition & 1 deletion
2
content/articles/leandrocfe-how-to-write-tests-for-filament-admin-panels.md
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
185 changes: 185 additions & 0 deletions
185
...articles/leandrocfe-navigating-filament-pages-with-previous-and-next-buttons.md
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,185 @@ | ||
--- | ||
title: Navigating Filament Pages with Previous and Next Buttons | ||
slug: leandrocfe-navigating-filament-pages-with-previous-and-next-buttons | ||
author_slug: leandrocfe | ||
publish_date: 2024-07-26 | ||
categories: [livewire, panel-builder] | ||
type_slug: article | ||
--- | ||
|
||
![Example](https://github.com/leandrocfe/article-fi-page-nav/blob/d36b3b7225adaace0aeb386455f6f1420f16f3d8/screenshots/example.gif?raw=true) | ||
|
||
|
||
## Introduction | ||
|
||
In this article, we will delve into the process of crafting previous and next navigation buttons within Filament pages. These buttons, designed as Filament Header Actions, can seamlessly navigate through ViewPages and EditPages. | ||
|
||
## Implementing New Actions | ||
|
||
To kick things off, we need to introduce two new actions: PreviousAction and NextAction. These actions will reside in the `app/Filament/Resources/Actions` folder. | ||
|
||
**PreviousAction.php** | ||
|
||
```php | ||
//app/Filament/Resources/Actions/PreviousAction.php | ||
namespace App\Filament\Resources\Actions; | ||
|
||
use Filament\Actions\Action; | ||
|
||
class PreviousAction extends Action | ||
{ | ||
public static function getDefaultName(): ?string | ||
{ | ||
return 'previous'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->hiddenLabel() | ||
->icon('heroicon-o-arrow-left') | ||
->outlined() | ||
->tooltip("Previous {$this->getRecordTitle()}"); | ||
} | ||
} | ||
``` | ||
|
||
**NextAction.php** | ||
|
||
```php | ||
//app/Filament/Resources/Actions/NextAction.php | ||
namespace App\Filament\Resources\Actions; | ||
|
||
use Filament\Actions\Action; | ||
|
||
class NextAction extends Action | ||
{ | ||
public static function getDefaultName(): ?string | ||
{ | ||
return 'next'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->hiddenLabel() | ||
->icon('heroicon-o-arrow-right') | ||
->outlined() | ||
->tooltip("Next {$this->getRecordTitle()}"); | ||
} | ||
} | ||
``` | ||
|
||
## Configuring Actions in Pages | ||
|
||
Next, we extend the capabilities of the ViewRecord and EditRecord classes by adding a `CanPaginateViewRecord` trait. This trait, residing in the `app/Filament/Resources/Pages/Concerns` folder, configures actions for pagination and provides methods to retrieve previous and next records based on the current record. | ||
|
||
```bash | ||
# Laravel 11 and higher | ||
php artisan make:trait Filament/Resources/Pages/Concerns/CanPaginateViewRecord | ||
|
||
# Laravel 10 create it manually | ||
``` | ||
|
||
```php | ||
namespace App\Filament\Resources\Pages\Concerns; | ||
|
||
use App\Filament\Resources\Actions\NextAction; | ||
use App\Filament\Resources\Actions\PreviousAction; | ||
use Filament\Actions\Action; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
trait CanPaginateViewRecord | ||
{ | ||
protected function configureAction(Action $action): void | ||
{ | ||
$this->configureActionRecord($action); | ||
|
||
match (true) { | ||
$action instanceof PreviousAction => $this->configurePreviousAction($action), | ||
$action instanceof NextAction => $this->configureNextAction($action), | ||
default => parent::configureAction($action), | ||
}; | ||
} | ||
|
||
protected function configurePreviousAction(Action $action): void | ||
{ | ||
if ($this->getPreviousRecord()) { | ||
$action->url(fn (): string => static::getResource()::getUrl(static::getResourcePageName(), ['record' => $this->getPreviousRecord()])); | ||
} else { | ||
$action | ||
->disabled() | ||
->color('gray'); | ||
} | ||
} | ||
|
||
protected function configureNextAction(Action $action): void | ||
{ | ||
if ($this->getNextRecord()) { | ||
$action->url(fn (): string => static::getResource()::getUrl(static::getResourcePageName(), ['record' => $this->getNextRecord()])); | ||
} else { | ||
$action | ||
->disabled() | ||
->color('gray'); | ||
} | ||
} | ||
|
||
protected function getPreviousRecord(): ?Model | ||
{ | ||
return $this | ||
->getRecord() | ||
->where('id', '<', $this->getRecord()->id) | ||
->orderBy('id', 'desc') | ||
->first(); | ||
} | ||
|
||
protected function getNextRecord(): ?Model | ||
{ | ||
return $this | ||
->getRecord() | ||
->where('id', '>', $this->getRecord()->id) | ||
->orderBy('id', 'asc') | ||
->first(); | ||
} | ||
} | ||
``` | ||
|
||
> **_NOTE:_** In this example, we use auto-incrementing IDs for the tables. If your tables are configured differently, you’ll need to adjust the `getPreviousRecord` and `getNextRecord` methods accordingly. | ||
## Usage Example | ||
|
||
Now, let's implement these actions in the **ViewRecord** and **EditRecord** pages. By including the `CanPaginateViewRecord` trait and registering the actions in the `getHeaderActions` array, you can enable previous and next navigation buttons. Below is an example using the ViewPost page: | ||
|
||
```php | ||
namespace App\Filament\Resources\PostResource\Pages; | ||
|
||
use App\Filament\Resources\Actions\NextAction; | ||
use App\Filament\Resources\Actions\PreviousAction; | ||
use App\Filament\Resources\Pages\Concerns\CanPaginateViewRecord; | ||
use App\Filament\Resources\PostResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ViewRecord; | ||
|
||
class ViewPost extends ViewRecord | ||
{ | ||
use CanPaginateViewRecord; | ||
|
||
protected static string $resource = PostResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\EditAction::make(), | ||
PreviousAction::make(), | ||
NextAction::make(), | ||
]; | ||
} | ||
} | ||
``` | ||
## Conclusion | ||
|
||
This project, including all the provided code, is available on [GitHub](https://github.com/leandrocfe/article-fi-page-nav). | ||
|
||
We hope you find this tutorial helpful in enhancing navigation within your Filament pages. Happy coding! |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,9 @@ | ||
--- | ||
name: Ngô Quốc Đạt | ||
slug: datlechin | ||
github_url: https://github.com/datlechin | ||
twitter_url: https://x.com/datlechin | ||
sponsor_url: https://github.com/sponsors/datlechin | ||
--- | ||
|
||
I'm a Software Developer from Vietnam and working on Laravel. |
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,7 @@ | ||
--- | ||
name: DigiFactory | ||
slug: digifactory | ||
github_url: https://github.com/digifactory | ||
--- | ||
|
||
DigiFactory is a Dutch webdevelopment agency specialized in building websites and applications. |
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,9 @@ | ||
--- | ||
name: Mücahit Uğur | ||
slug: oriondevelops | ||
github_url: https://github.com/oriondevelops | ||
twitter_url: https://twitter.com/oriondevelops | ||
sponsor_url: https://github.com/sponsors/oriondevelops | ||
--- | ||
|
||
A solopreneur based in İstanbul. |
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,6 @@ | ||
--- | ||
name: Stephen Jude | ||
slug: stephenjude | ||
github_url: https://github.com/stephenjude | ||
twitter_url: https://twitter.com/stephenjude_ | ||
--- |
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,9 @@ | ||
--- | ||
name: Teguh Rijanandi | ||
slug: teguhrijanandi | ||
github_url: https://github.com/teguh02 | ||
twitter_url: https://twitter.com/teguhnandi | ||
sponsor_url: https://github.com/sponsors/teguh02 | ||
--- | ||
|
||
Teguh Rijanandi is a full-stack developer and researcher with a substantial background in application development. He is proficient in a wide range of technologies, including Laravel, React (including React Native), and Vue.js |
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,11 @@ | ||
--- | ||
name: Visual Builder | ||
slug: visual-builder | ||
github_url: https://github.com/visualbuilder | ||
twitter_url: https://twitter.com/cannycookie | ||
--- | ||
|
||
I started coding in 1983 on a ZX-81 and been a geeky coder ever since. | ||
Now focused on creating business automation tools with Laravel and Filament. | ||
With Visual Builder my team and I are working on publishing a suite of tools that we've found essential when creating business apps. | ||
We hope they will make creating apps faster and less repetitive and provide a better customer experience. |
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,14 @@ | ||
--- | ||
name: Bookmarks Menu | ||
slug: 3x1io-tomato-bookmarks-menu | ||
author_slug: 3x1io | ||
categories: [developer-tool] | ||
description: Add bookmarks and tags to your resources records and access theme form your sidebar | ||
discord_url: https://discord.com/channels/883083792112300104/1265002822605344871 | ||
docs_url: https://raw.githubusercontent.com/tomatophp/filament-bookmarks-menu/master/README.md | ||
github_repository: tomatophp/filament-bookmarks-menu | ||
has_dark_theme: true | ||
has_translations: true | ||
versions: [3] | ||
publish_date: 2024-09-07 | ||
--- |
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,14 @@ | ||
--- | ||
name: Invoices Manager | ||
slug: 3x1io-tomato-invoices | ||
author_slug: 3x1io | ||
categories: [developer-tool] | ||
description: Generate and manage your invoices / payments using multi currencies and multi types in FilamentPHP | ||
discord_url: https://discord.com/channels/883083792112300104/1265002822605344871 | ||
docs_url: https://raw.githubusercontent.com/tomatophp/filament-invoices/master/README.md | ||
github_repository: tomatophp/filament-invoices | ||
has_dark_theme: true | ||
has_translations: true | ||
versions: [3] | ||
publish_date: 2024-08-30 | ||
--- |
Oops, something went wrong.