Replies: 1 comment 1 reply
-
Here are some improvements: <?php
namespace App\Filament\Resources\UserResource\RelationManagers;
use App\Filament\Resources\OrderResource;
use App\Models\Order;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables\Actions\EditAction;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Auth;
class OrdersRelationManager extends RelationManager
{
protected static string $relationship = 'orders';
public static function getPluralModelLabel(): string
{
return 'Pedidos';
}
public static function table(Table $table): Table
{
return OrderResource::table($table)
->filters([])
->actions([
EditAction::make()
->url(fn (Order $record): string => OrderResource::getUrl('edit', ['record' => $record])),
])
->bulkActions([])
->headerActions([]);
}
protected function getTableQuery(): Builder | Relation
{
return OrderResource::getEloquentQuery()
->where('user_id', $this->ownerRecord->id);
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was looking to implement a relationship manager similar to Nova, where you just reference the relationship in question and it automatically generates the table, reusing the same columns, query, etc.
I also didn't want to have filters, bulkActions, headerActions, etc. Just a simple table, with an Edit button that takes you to the Edit page (no modals please).
Here's what I did:
What I did was:
Beta Was this translation helpful? Give feedback.
All reactions