我正在使用 laravel 默认数据库通知,我想将软删除添加到通知表中。
我已经创建了一个带有软删除的迁移,该迁移已将deleted_at列添加到通知表中。问题是我必须将">使用软删除"添加到通知模型(根据 laravel 文档(,但找不到通知模型。
$table->softDeletes();
我尝试将">使用软删除"添加到HasDatabaseNotifications特征中,但它仍然删除了该行。有没有另一种方法可以将软删除添加到通知表。蒂亚
在开始类使用之前位于顶部的模型中
use IlluminateDatabaseEloquentSoftDeletes;
课后
class Notification extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
}
这就是我解决它的方式,希望对您和其他朋友有用
App\Classes\MyDatabaseNotification.php
namespace AppClasses;
use IlluminateDatabaseEloquentSoftDeletes;
use IlluminateNotificationsDatabaseNotification;
class MyDatabaseNotification extends DatabaseNotification
{
use SoftDeletes;
protected $dates = ['deleted_at'];
}
App\Classes\MyNotifiable.php
namespace AppClasses;
use IlluminateNotificationsNotifiable;
trait MyNotifiable
{
use Notifiable;
/**
* Get the entity's notifications.
*/
public function notifications()
{
return $this->morphMany(MyDatabaseNotification::class, 'notifiable')
->orderBy('created_at', 'desc');
}
}
应用\用户.php
namespace AppModels;
use IlluminateFoundationAuthUser as Authenticatable;
use AppClassesMyNotifiable;
...
class User extends Authenticatable
{
use MyNotifiable;
...