首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在$request->user()->notifications()中返回自定义类?

如何在$request->user()->notifications()中返回自定义类?
EN

Stack Overflow用户
提问于 2022-11-22 05:33:51
回答 1查看 21关注 0票数 0

在laravel/Framework9.1管理区使用兰花/crud 3.8和兰花/平台13.6自定义通知,我必须添加兰花AsSource特性来照亮\通知\DatabaseNotification类,这将使我有可能在兰花屏幕中使用这个类,因此我需要转换数据App\Model\兰花\DatabaseNotification(我从照明\通知\DatabaseNotification和添加了AsSource特性复制了这个类)。

代码语言:javascript
复制
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. 我可以重做$
  2. ->user()->notifications()来返回data \Models\orchid\DatabaseNotification ?
  3. Tracing $notifications var,我看到它收集并具有数据属性。但是当我尝试调试

代码语言:javascript
复制
$notifications->data 

我有错误:

代码语言:javascript
复制
has Undefined property: Illuminate\Pagination\LengthAwarePaginator::$data

我可以手动替换LengthAwarePaginator::$data吗?

如果有办法解决它呢?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-22 05:48:56

是的,您可以重新制作$request->user()->notifications() --在获取数据时只需使用它的模型:

代码语言:javascript
复制
DatabaseNotification::query()
    ->where('notifiable_id', Auth()->id())
    ->where('type', DashboardMessage::class)
    ->paginate(10);

ps。我不太明白第二个问题,但试试看我先给出的答案。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74527916

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档