Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将单个Laravel通知标记为已读_Php_Laravel - Fatal编程技术网

Php 将单个Laravel通知标记为已读

Php 将单个Laravel通知标记为已读,php,laravel,Php,Laravel,我的应用程序中有一个页面,显示用户当前所有未读通知的列表,每个通知都有一个已读图标 数据库中的ID设置为char,因此是一个长的字母和数字字符串。当我在页面上显示通知的id时,它们都返回与数据库中的内容无关的数字,因此当我运行查询以读取通知时,它找不到id,因为id不匹配 在Laravel中读取单个通知的最佳方法是什么?我正在使用下面的代码进行尝试,但是$request->get'id'是不正确的,因为我似乎得到了12310作为一个id,有些甚至是0 Auth::user()->unrea

我的应用程序中有一个页面,显示用户当前所有未读通知的列表,每个通知都有一个已读图标

数据库中的ID设置为char,因此是一个长的字母和数字字符串。当我在页面上显示通知的id时,它们都返回与数据库中的内容无关的数字,因此当我运行查询以读取通知时,它找不到id,因为id不匹配

在Laravel中读取单个通知的最佳方法是什么?我正在使用下面的代码进行尝试,但是$request->get'id'是不正确的,因为我似乎得到了12310作为一个id,有些甚至是0

Auth::user()->unreadNotifications->where('id', $request->get('id'))->markAsRead()

上述函数将返回一个数组use first方法: $note=Auth::user->unreadNotifications->where'id',$request->get'id'->first->get;
$note->markAsRead

上述函数将返回一个数组使用第一种方法: $note=Auth::user->unreadNotifications->where'id',$request->get'id'->first->get; $note->markAsRead

Laravel notifications表的id使用CHAR作为默认字段类型。所以,当你过滤某个id时,你必须先使用下面的方法。因为未指定的通知是Lightning\Notifications\DatabaseNotificationCollection

Laravel notifications表的id使用CHAR作为默认字段类型。所以,当你过滤某个id时,你必须先使用下面的方法。因为未指定的通知是Lightning\Notifications\DatabaseNotificationCollection

Laravel notifications表的id使用CHAR作为默认字段类型。因此,当您筛选某个id时,您必须首先使用以下方法

我的xxx.blade.phpis:

最后在我的VendorsController@comment_replay功能如下:


    public function comment_replay($id)
    {
        $userUnreadNotification = auth()->user()
                                        ->unreadNotifications
                                        ->where('id', $id)
                                        ->first();
    
        if($userUnreadNotification) {
            $userUnreadNotification->markAsRead();
        }
    }
Laravel notifications表的id使用CHAR作为默认字段类型。因此,当您筛选某个id时,您必须首先使用以下方法

我的xxx.blade.phpis:

最后在我的VendorsController@comment_replay功能如下:


    public function comment_replay($id)
    {
        $userUnreadNotification = auth()->user()
                                        ->unreadNotifications
                                        ->where('id', $id)
                                        ->first();
    
        if($userUnreadNotification) {
            $userUnreadNotification->markAsRead();
        }
    }

如果您可以提供一些代码,其他代码可以更好地帮助您。在执行任何操作之前,请正确键入并强制转换这些代码。您的意思是说存储在数据库中的字符数据与显示的字符数据不同?问题1:如何将字符数据存储在数据库中?如果您可以提供一些代码,其他代码可以更好地帮助您。请在执行任何操作之前正确地键入cast。您的意思是说存储在数据库中的字符数据与display不相同?问题1:如何在数据库中存储字符数据?
    Route::get('comment-replay/{id}','VendorsController@comment_replay')->name('commentReplay');

    public function comment_replay($id)
    {
        $userUnreadNotification = auth()->user()
                                        ->unreadNotifications
                                        ->where('id', $id)
                                        ->first();
    
        if($userUnreadNotification) {
            $userUnreadNotification->markAsRead();
        }
    }