mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
create model notification added
This commit is contained in:
66
app/Notifications/ModelCreatedNotification.php
Normal file
66
app/Notifications/ModelCreatedNotification.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
|
||||||
|
class ModelCreatedNotification extends Notification
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new notification instance.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(public $model, public string $resource)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the notification's delivery channels.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return ['mail'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the mail representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||||
|
*/
|
||||||
|
public function toMail($notifiable)
|
||||||
|
{
|
||||||
|
return (new MailMessage)
|
||||||
|
->subject('New model created: '.get_class($this->model))
|
||||||
|
->line('Model: '.get_class($this->model))
|
||||||
|
->action('Show', url('/nova/resources/'.$this->resource))
|
||||||
|
->line(' ')
|
||||||
|
->line(' ')
|
||||||
|
->line(' ')
|
||||||
|
->line($this->model->toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the array representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($notifiable)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Nova;
|
namespace App\Nova;
|
||||||
|
|
||||||
|
use App\Notifications\ModelCreatedNotification;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Laravel\Nova\Fields\BelongsTo;
|
use Laravel\Nova\Fields\BelongsTo;
|
||||||
use Laravel\Nova\Fields\HasMany;
|
use Laravel\Nova\Fields\HasMany;
|
||||||
@@ -9,6 +11,7 @@ use Laravel\Nova\Fields\HasManyThrough;
|
|||||||
use Laravel\Nova\Fields\ID;
|
use Laravel\Nova\Fields\ID;
|
||||||
use Laravel\Nova\Fields\Number;
|
use Laravel\Nova\Fields\Number;
|
||||||
use Laravel\Nova\Fields\Text;
|
use Laravel\Nova\Fields\Text;
|
||||||
|
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||||
|
|
||||||
class City extends Resource
|
class City extends Resource
|
||||||
{
|
{
|
||||||
@@ -23,12 +26,6 @@ class City extends Resource
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public static $title = 'name';
|
public static $title = 'name';
|
||||||
|
|
||||||
public static function label()
|
|
||||||
{
|
|
||||||
return __('City');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The columns that should be searched.
|
* The columns that should be searched.
|
||||||
* @var array
|
* @var array
|
||||||
@@ -38,6 +35,20 @@ class City extends Resource
|
|||||||
'name',
|
'name',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public static function label()
|
||||||
|
{
|
||||||
|
return __('City');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function afterCreate(NovaRequest $request, Model $model)
|
||||||
|
{
|
||||||
|
\App\Models\User::find(1)
|
||||||
|
->notify(new ModelCreatedNotification($model, str($request->getRequestUri())
|
||||||
|
->after('/nova-api/')
|
||||||
|
->before('?')
|
||||||
|
->toString()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the fields displayed by the resource.
|
* Get the fields displayed by the resource.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user