--- /dev/null
+<?php
+
+namespace App\Notifications;
+
+use App\Mail\MailMessage;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Notifications\Notification;
+
+class JustSubscribed extends Notification
+{
+ use Queueable;
+
+ /**
+ * Create a new notification instance.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ //
+ }
+
+ /**
+ * 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)
+ {
+ $message = (new MailMessage)
+ ->subject('PRESCRIPTION SANTÉ QUOTIDIEN : Abonnement activé !')
+ ->line('Votre abonnement à PRESCRIPTION SANTÉ QUOTIDIEN est désormais actif !')
+ ->addTag('just-subscribed');
+
+
+ if($notifiable->reg_complete) {
+ $message->line("Votre compte est déjà activé, vous n'avez rien de plus à faire.");
+ } else {
+ $link = $notifiable->routeWithToken('account.index', [], now()->addDays(7));
+ $message
+ ->line("En cliquant sur le bouton ci-dessous vous devez vous créer un mot de passe.")
+ ->action('Créer mon mot de passe', $link)
+ ->line("Cela ne prendra pas plus d'une minute !");
+ }
+
+ return $message;
+
+ }
+
+ /**
+ * Get the array representation of the notification.
+ *
+ * @param mixed $notifiable
+ * @return array
+ */
+ public function toArray($notifiable)
+ {
+ return [
+ //
+ ];
+ }
+}
{
return [
Select::make('Notification')->options([
- Notifications\Welcome::class => 'Message de bienvenue',
+// Notifications\Welcome::class => 'Message de bienvenue',
Notifications\RegistrationPending::class => 'Rappel',
+ Notifications\JustSubscribed::class => 'Message abonnement activé'
])
];
}
--- /dev/null
+<?php
+
+namespace App\Nova\Actions;
+
+use App\Notifications\JustSubscribed;
+use App\Nova\Organization;
+use App\User;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Support\Collection;
+use Laravel\Nova\Actions\Action;
+use Laravel\Nova\Fields\ActionFields;
+use Laravel\Nova\Fields\BelongsTo;
+use Laravel\Nova\Fields\Boolean;
+use Laravel\Nova\Fields\Select;
+
+class SubscribeUser extends Action
+{
+ use InteractsWithQueue, Queueable;
+
+ public $showOnTableRow = true;
+ public $name = "Activer abonnement";
+ /**
+ * Perform the action on the given models.
+ *
+ * @param \Laravel\Nova\Fields\ActionFields $fields
+ * @param \Illuminate\Support\Collection $models
+ * @return mixed
+ */
+ public function handle(ActionFields $fields, Collection $models)
+ {
+ $users = $models->filter(fn($user) => $user->type !== User::TYPE_SUBSCRIBER);
+
+ $users->map(function(User $user) use($fields) {
+
+ $user->type = User::TYPE_SUBSCRIBER;
+ $user->organization()->associate(\App\Organization::query()->findOrFail($fields->org_id));
+ $user->save();
+ if(! $fields->dont_notify) {
+ $user->notify(new JustSubscribed);
+ }
+ });
+
+ return Action::message(count($users). " abonnements activés !");
+ }
+
+ /**
+ * Get the fields available on the action.
+ *
+ * @return array
+ */
+ public function fields()
+ {
+ return [
+ Select::make('Organisation', 'org_id')->options(
+ \App\Organization::query()
+ ->orderBy('name')
+ ->where('subscription_active', 1)
+ ->get()
+ ->pluck('name', 'id')
+
+ )->searchable(),
+ Boolean::make("Ne pas notifier", 'dont_notify')
+ ];
+ }
+}
namespace App\Nova;
+use App\Nova\Actions\SubscribeUser;
use Carbon\Carbon;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\Text;
+use Illuminate\Http\Request;
use Laravel\Nova\Http\Requests\NovaRequest;
class DiscoverUsers extends User
];
}
+ public function actions(Request $request)
+ {
+ return array_merge(parent::actions($request), [
+ new SubscribeUser,
+ ]);
+ }
}
namespace App\Nova;
+use App\Nova\Actions\SubscribeUser;
+use Illuminate\Http\Request;
use Laravel\Nova\Http\Requests\NovaRequest;
class Prospect extends User
return "Prospect";
}
+ public function actions(Request $request)
+ {
+ return array_merge(parent::actions($request), [
+ new SubscribeUser,
+ ]);
+ }
+
}