Home > Blockchain >  How can I in $request->user()->notifications() return custom class?
How can I in $request->user()->notifications() return custom class?

Time:11-22

Making in laravel/framework 9.1 admin area with orchid/crud 3.8 and orchid/platform 13.6 custom notifications I have to add orchid AsSource trait for Illuminate\Notifications\DatabaseNotification class - that will give me possibility to use this class in orchid screens so I need to convert data App\Models\orchid\DatabaseNotification (I copied this class from Illuminate\Notifications\DatabaseNotification and added AsSource trait )

use App\Models\orchid\DatabaseNotification; // My custom class
//use Illuminate\Notifications\DatabaseNotification;

class CustomAdminNotificationsScreen extends Screen
{

    public function query(Request $request): iterable
    {
        /** @var Paginator $notifications */


        $notifications = $request->user()
                                 ->notifications()
                                 ->where('type', DashboardMessage::class)
                                 ->paginate(10);
                                 /// This data have  Illuminate\\Notifications\\DatabaseNotification class claas
  1. Can I remake $request->user()->notifications() to return data App\Models\orchid\DatabaseNotification ?
  2. Tracing $notifications var I see that it Collection and has data property. But when I try to debug
$notifications->data 

I got error :

has Undefined property: Illuminate\Pagination\LengthAwarePaginator::$data

Can I replace LengthAwarePaginator::$data manually ?

If there is a way how to fix it ?

Thanks!

CodePudding user response:

Yes, you can remake the $request->user()->notifications() you can just use its model when getting the data :

DatabaseNotification::query()
    ->where('notifiable_id', Auth()->id())
    ->where('type', DashboardMessage::class)
    ->paginate(10);

ps. I don't quite understand the second question but try answer I given first.

  • Related