Skip to content

Commit

Permalink
Merge branch 'filamentphp:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa authored Sep 9, 2024
2 parents 832e51a + 58cad90 commit dbad2dd
Show file tree
Hide file tree
Showing 416 changed files with 25,836 additions and 14,460 deletions.
19 changes: 19 additions & 0 deletions app/Http/Controllers/Api/AuthorController.php
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');
}
}
8 changes: 8 additions & 0 deletions app/Models/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
Expand Down Expand Up @@ -63,6 +64,13 @@ public function getStarsCount(): int
);
}

protected function starsCount(): Attribute
{
return Attribute::make(
get: fn () => $this->getStarsCount(),
);
}

public function cacheStarsCount(): void
{
cache()->forget($this->getStarsCountCacheKey());
Expand Down
4 changes: 2 additions & 2 deletions content/articles/leandrocfe-brazilian-cpfcnpj-field.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Brazilian CPF CNPJ fields
slug: brazilian-cpfcnpj-field
slug: leandrocfe-brazilian-cpfcnpj-field
author_slug: leandrocfe
publish_date: 2023-03-01
categories: [form-builder, alpinejs]
Expand Down Expand Up @@ -87,4 +87,4 @@ TextInput::make('cpf')
TextInput::make('cnpj')
->extraAlpineAttributes(['x-mask' => '99.999.999/9999-99'])
->rule('cnpj')
```
```
4 changes: 2 additions & 2 deletions content/articles/leandrocfe-brazilian-phone-number-field.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Brazilian Phone Number field
slug: brazilian-phone-number-field
slug: leandrocfe-brazilian-phone-number-field
author_slug: leandrocfe
publish_date: 2022-12-05
categories: [form-builder, alpinejs]
Expand Down Expand Up @@ -45,4 +45,4 @@ public function boot()
```php
TextInput::make('phone_number')
->extraAlpineAttributes(['x-mask:dynamic' => '$input.length >=14 ? \'(99)99999-9999\' : \'(99)9999-9999\''])
```
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Easy way to create a Filament Theme in minutes!
slug: easy-way-to-create-a-filament-theme-in-minutes
slug: leandrocfe-easy-way-to-create-a-filament-theme-in-minutes
author_slug: leandrocfe
publish_date: 2022-10-21
categories: [panel-builder, tailwind-css]
Expand Down Expand Up @@ -311,4 +311,4 @@ npm run build && php artisan serve

Once you have started the Artisan development server, your application will be accessible in your web browser at <http://127.0.0.1:8000/admin>. You can choose a user's credentials and authenticate to access the Filament Admin Panel (default password: **password**).

You can download this project on GitHub: [leandrocfe/filament-custom-theme](https://github.com/leandrocfe/filament-custom-theme)
You can download this project on GitHub: [leandrocfe/filament-custom-theme](https://github.com/leandrocfe/filament-custom-theme)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: How to consume an external API with Filament Tables
slug: how-to-consume-an-external-api-with-filament-tables
slug: leandrocfe-how-to-consume-an-external-api-with-filament-tables
author_slug: leandrocfe
publish_date: 2022-10-28
categories: [panel-builder, table-builder, integration]
Expand Down Expand Up @@ -235,4 +235,4 @@ protected function getActions(): array

Visit your **Product Resource** at **/admin/products** to try it! Hope you enjoy!

You can download this project on GitHub: <https://github.com/leandrocfe/filament-tables-json-data-source>
You can download this project on GitHub: <https://github.com/leandrocfe/filament-tables-json-data-source>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: How to Refresh Widgets When Table Actions Are Fired
slug: how-to-refresh-widgets-when-table-actions-are-fired
slug: leandrocfe-how-to-refresh-widgets-when-table-actions-are-fired
author_slug: leandrocfe
publish_date: 2023-03-04
categories: [livewire, panel-builder, table-builder]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: How to write tests for Filament admin panels
slug: how-to-write-tests-for-filament-admin-panels
slug: leandrocfe-how-to-write-tests-for-filament-admin-panels
author_slug: leandrocfe
publish_date: 2022-11-06
categories: [laravel, livewire, panel-builder, table-builder, form-builder]
Expand Down
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!
Binary file added content/authors/avatars/datlechin.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/authors/avatars/digifactory.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/authors/avatars/oriondevelops.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/authors/avatars/stephenjude.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/authors/avatars/teguhrijanandi.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/authors/avatars/visual-builder.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions content/authors/awcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Adam Weston
slug: awcodes
github_url: https://github.com/awcodes
twitter_url: https://twitter.com/awcodes1
sponsor_url: https://github.com/sponsors/awcodes
---

Adam is a full-stack web developer (with a focus on Laravel) who has been coding for close to 20 years. He is a core Filament team member as well and has authored numerous plugins for Filament such as [Curator](/plugins/awcodes-curator), [Tiptap Editor](/plugins/awcodes-tiptap-editor) and [Table Repeater](/plugins/awcodes-table-repeater), to name a few. You can learn more about Adam on his [website](https://aw.codes).
9 changes: 9 additions & 0 deletions content/authors/datlechin.md
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.
7 changes: 7 additions & 0 deletions content/authors/digifactory.md
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.
9 changes: 9 additions & 0 deletions content/authors/oriondevelops.md
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.
6 changes: 6 additions & 0 deletions content/authors/stephenjude.md
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_
---
9 changes: 9 additions & 0 deletions content/authors/teguhrijanandi.md
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
11 changes: 11 additions & 0 deletions content/authors/visual-builder.md
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.
14 changes: 14 additions & 0 deletions content/plugins/3x1io-tomato-bookmarks-menu.md
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
---
14 changes: 14 additions & 0 deletions content/plugins/3x1io-tomato-invoices.md
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
---
Loading

0 comments on commit dbad2dd

Please sign in to comment.