filament icon indicating copy to clipboard operation
filament copied to clipboard

Database Notifications Not work When i Use Postgres

Open mstfkhazaal opened this issue 1 year ago • 2 comments

Package

filament/filament

Package Version

v3.2.117

Laravel Version

v11.27.2

Livewire Version

No response

PHP Version

PHP 8.2

Problem description

Database Notifications Not work When i Use Postgres

I get this error:

SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: text ->> unknown LINE 1: 
...ifications"."notifiable_id" is not null and "data"->>'format... ^ HINT: No operator matches the given name and argument
types. You might need to add explicit type casts. (Connection: pgsql, SQL: select * from "notifications" where
"notifications"."notifiable_type" = App\Models\User\User and "notifications"."notifiable_id" = 1 and
"notifications"."notifiable_id" is not null and "data"->>'format' = filament order by "created_at" desc limit 51 offset 0)

CleanShot 2024-10-12 at 18 28 36@2x

Expected behavior

Work Normal

Steps to reproduce

  1. Clone Repository https://github.com/mstfkhazaal/postgres_notification/
  2. Install Postgres or use via Laravel Sail (sail up -d)
  3. Run this codes
cp .env.example .env
php artisan key:generate
php artisan migrate:fresh --seed
  1. Got To http://localhost/admin/login
  2. Login: Email: [email protected] Password: password

Reproduction repository (issue will be closed if this is not valid)

https://github.com/mstfkhazaal/postgres_notification/

Relevant log output

SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: text ->> unknown LINE 1: 
...ifications"."notifiable_id" is not null and "data"->>'format... ^ HINT: No operator matches the given name and argument
types. You might need to add explicit type casts. (Connection: pgsql, SQL: select * from "notifications" where
"notifications"."notifiable_type" = App\Models\User\User and "notifications"."notifiable_id" = 1 and
"notifications"."notifiable_id" is not null and "data"->>'format' = filament order by "created_at" desc limit 51 offset 0)

Donate 💰 to fund this issue

  • You can donate funding to this issue. We receive the money once the issue is completed & confirmed by you.
  • 100% of the funding will be distributed between the Filament core team to run all aspects of the project.
  • Thank you in advance for helping us make maintenance sustainable!
Fund with Polar

mstfkhazaal avatar Oct 12 '24 15:10 mstfkhazaal

Hi there. It seems your repo does not have the Notifications table migration, according to the docs:

https://filamentphp.com/docs/3.x/notifications/database-notifications#setting-up-the-notifications-database-table

Setting up the notifications database table

Before we start, make sure that the Laravel notifications table is added to your database:

Laravel 11 and higher

php artisan make:notifications-table

Laravel 10

php artisan notifications:table

If you're using PostgreSQL, make sure that the data column in the migration is using json(): $table->json('data').

If you're using UUIDs for your User model, make sure that your notifiable column is using uuidMorphs(): $table->uuidMorphs('notifiable').

sjardim avatar Oct 16 '24 18:10 sjardim

I had the same problem and solved it by changing: $table->text('data'); to $table->json('data'); in notifications migration!

mahdimirhendi avatar Oct 19 '24 22:10 mahdimirhendi

I also have this problem. my finding is the operator not working in postgres 9.2 or earlier, the operator '->>' maybe only work in postgre 9.3 and newer.

dennyvik avatar Oct 24 '24 18:10 dennyvik

Thanks @mahdimirhendi

danharrin avatar Dec 11 '24 11:12 danharrin

it's work. thanks @mahdimirhendi

mhdiorevansa avatar Dec 28 '24 02:12 mhdiorevansa