push通知のライブラリ入れる細かい設定は他サイト参照
composer require laravel-notification-channels/webpush
※以下neo4jで注意する点
デフォルトのモデルはNeoEloquentを使っていないので変更
config/webpush.php
'model' => \App\Models\PushSubscription::class,
モデル
app/Models/PushSubscription.php
<?php
namespace App\Models;
use Vinelab\NeoEloquent\Eloquent\Model as NeoEloquent;
/**
* @property string $endpoint
* @property string|null $public_key
* @property string|null $auth_token
* @property string|null $content_encoding
* @property \Illuminate\Database\Eloquent\Model $subscribable
*/
class PushSubscription extends NeoEloquent
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $label = 'PushSubscriptions';
protected $fillable = [
'endpoint',
'public_key',
'auth_token',
'content_encoding',
];
/**
* Create a new model instance.
*
* @param array $attributes
* @return void
*/
public function __construct(array $attributes = [])
{
if (! isset($this->connection)) {
$this->setConnection(config('webpush.database_connection'));
}
if (! isset($this->table)) {
$this->setTable(config('webpush.table_name'));
}
parent::__construct($attributes);
}
/**
* Get the model related to the subscription.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function subscribable()
{
return $this->morphTo();
}
/**
* Find a subscription by the given endpint.
*
* @param string $endpoint
* @return static|null
*/
public static function findByEndpoint($endpoint)
{
return static::where('endpoint', $endpoint)->first();
}
}