filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
19.29k stars 2.96k forks source link

\RelationManager::getTableRecordTitle(): Argument #1 ($record) must be of type Illuminate\Database\Eloquent\Model, null given, called in on line 89 #6896

Closed godlikeAlex closed 11 months ago

godlikeAlex commented 1 year ago

Package

filament/filament

Package Version

v2.16.58

Laravel Version

9.45.1

Livewire Version

v2.10.7

PHP Version

8.2.7

Problem description

I have Product, ProductOption, ProductAddon model, and relation many to many (Product belongsToMany ProductOption belongsToMany ProductAddon)

I created resource for product and relation manager for ProductResource

ProductResource:

  public static function getRelations(): array
  {
    return [OptionsRelationManager::class, AddonsRelationManager::class];
  }

OptionsRelationManager and AddonsRelationManager has SoftDeletes functionality, but restore action not working. (Bulk Restore Action works perfectly!)

RestoreAction error: Filament\Resources\RelationManagers\RelationManager::getTableRecordTitle(): Argument #1 ($record) must be of type Illuminate\Database\Eloquent\Model, null given, called in /Users/aleksand/Sites/signs365/vendor/filament/tables/src/Actions/Action.php on line 89

Expected behavior

Restore functionality :D

Steps to reproduce

Need create Product in admin Panel, then Product has Relation Manager at the bottom of the product page, you need create "Option" <- (this relation in product page)

Then need delete this option, after delete need restore it (error happens)

Reproduction repository

https://github.com/godlikeAlex/signs365-laravel

Relevant log output

No response

e-smily commented 1 year ago

filament/tables Version v2.17.49 Laravel 9.1.9 Livewire v2.1.2 PHP 8.1.10

I got the following error when try to restore or delete soft-deletes (RestoreAction / ForceDeleteAction)

App\Http\Livewire\Objekt::getTableRecordTitle(): Argument #1 ($record) must be of type Illuminate\Database\Eloquent\Model, null given, called in D:\laragon\www\test\filament\filament-table\vendor\filament\tables\src\Actions\Action.php on line 89

Habib2014 commented 1 year ago

i have the same problem.. getTableRecordTitle(): Argument https://github.com/filamentphp/filament/pull/1 ($record) must be of type Illuminate\Database\Eloquent\Model, null given, called in D:\laragon\www\test\filament\filament-table\vendor\filament\tables\src\Actions\Action.php on line 89

wannesmatthys commented 1 year ago

filament/tables Version v2.17.49 Laravel 9.1.9 Livewire v2.1.2 PHP 8.1.10

I got the following error when try to restore or delete soft-deletes (RestoreAction / ForceDeleteAction)

App\Http\Livewire\Objekt::getTableRecordTitle(): Argument #1 ($record) must be of type Illuminate\Database\Eloquent\Model, null given, called in D:\laragon\www\test\filament\filament-table\vendor\filament\tables\src\Actions\Action.php on line 89

Hi, did you find a fix by any chance? I'm facing the same problem.

danharrin commented 1 year ago

Can anyone confirm if this is an issue in v3 or just v2?

psyao commented 1 year ago

I tried with : filament/filament v3.0.69 Laravel 10.26.2 Livewire 3.0.5 PHP 8.2.10

and didn't met this bug but can confirm it happens on filament/filament 2.17.*

dvdmtchln commented 1 year ago

I solved the issue. All you need to do is override the getTableQuery method in your RelationManager like so:

protected function getTableQuery(): Builder|Relation
{
    return parent::getTableQuery()->withoutGlobalScopes([SoftDeletingScope::class]);
}
realyukii commented 1 year ago

@psyao how you update the package? I try to use composer update filament/filament but nothing happend

and also composer require filament/filament --update-with-dependencies show conflict error

ahmadxgani commented 1 year ago

@danharrin how to properly update this package to v3?

ahmadxgani commented 1 year ago

It seems updating to v3 is causing conflict in my dependency; how can I solve this?

$ composer require filament/filament:3.0.80
./composer.json has been updated
Running composer update filament/filament
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires filament/filament 3.0.80, found filament/filament[v3.0.80] but these were not loaded, likely because it conflicts with another require.
  Problem 2
    - bezhansalleh/filament-exceptions is locked to version 1.1.2 and an update of this package was not requested.
    - bezhansalleh/filament-exceptions 1.1.2 requires filament/filament ^2.0 -> found filament/filament[v2.0.0-beta1, ..., 2.x-dev] but it conflicts with your root composer.json require (3.0.80).
  Problem 3
    - bezhansalleh/filament-shield is locked to version 2.4.8 and an update of this package was not requested.
    - bezhansalleh/filament-shield 2.4.8 requires filament/filament ^2.13 -> found filament/filament[v2.13.0-beta1, ..., 2.x-dev] but it conflicts with your root composer.json require (3.0.80).
  Problem 4
    - filipfonal/filament-log-manager is locked to version 1.3.0 and an update of this package was not requested.
    - filipfonal/filament-log-manager 1.3.0 requires filament/filament ^2.10 -> found filament/filament[v2.10.0-beta1, ..., 2.x-dev] but it conflicts with your root composer.json require (3.0.80).
  Problem 5
    - konnco/filament-import is locked to version 1.6.0 and an update of this package was not requested.
    - konnco/filament-import 1.6.0 requires filament/filament ^2.0 -> found filament/filament[v2.0.0-beta1, ..., 2.x-dev] but it conflicts with your root composer.json require (3.0.80).
  Problem 6
    - shuvroroy/filament-spatie-laravel-backup is locked to version v1.3.1 and an update of this package was not requested.
    - shuvroroy/filament-spatie-laravel-backup v1.3.1 requires filament/filament ^2.0 -> found filament/filament[v2.0.0-beta1, ..., 2.x-dev] but it conflicts with your root composer.json require (3.0.80).

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.
danharrin commented 1 year ago

This is not the place for help upgrading, please ask patiently on Discord.

AhmedAtiyah commented 12 months ago

@danharrin I got the same issue in V2, I implemented a deleteAction. It works but then returns this error. Locally it didnt happen, but in production it sometimes happen.

danharrin commented 11 months ago

I have created a relation manager in v3. Soft deletes are enabled. There is a TrashedFilter. There is DeleteAction, RestoreAction and ForceDeleteAction.

Seems to work just fine:

https://github.com/filamentphp/filament/assets/41773797/0748c54d-bb0f-412e-b7ac-fd35094bdb9b

If someone is experiencing this behaviour in v3, please send me a reproduction repository.