From 5d6de66e3d667ca3da576c2853e54d9eb477e808 Mon Sep 17 00:00:00 2001 From: Benjamin Takats Date: Thu, 15 Dec 2022 11:39:26 +0100 Subject: [PATCH] create model notification added --- .../ModelCreatedNotification.php | 66 +++++++++++++++++++ app/Nova/City.php | 23 +++++-- 2 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 app/Notifications/ModelCreatedNotification.php diff --git a/app/Notifications/ModelCreatedNotification.php b/app/Notifications/ModelCreatedNotification.php new file mode 100644 index 00000000..b4c5b65e --- /dev/null +++ b/app/Notifications/ModelCreatedNotification.php @@ -0,0 +1,66 @@ +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 [ + // + ]; + } +} diff --git a/app/Nova/City.php b/app/Nova/City.php index a1bdc6b7..3fd91eae 100644 --- a/app/Nova/City.php +++ b/app/Nova/City.php @@ -2,6 +2,8 @@ namespace App\Nova; +use App\Notifications\ModelCreatedNotification; +use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; use Laravel\Nova\Fields\BelongsTo; use Laravel\Nova\Fields\HasMany; @@ -9,6 +11,7 @@ use Laravel\Nova\Fields\HasManyThrough; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Number; use Laravel\Nova\Fields\Text; +use Laravel\Nova\Http\Requests\NovaRequest; class City extends Resource { @@ -23,12 +26,6 @@ class City extends Resource * @var string */ public static $title = 'name'; - - public static function label() - { - return __('City'); - } - /** * The columns that should be searched. * @var array @@ -38,6 +35,20 @@ class City extends Resource '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. *