-
app/Http/Controllers/OfficeController.php
Open in GitHubuse App\Http\Resources\OfficeResource; use App\Models\Office; use App\Notifications\OfficePendingApproval; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Notification; class OfficeController extends Controller { // public function show(Office $office): JsonResource { $office->loadCount(['reservations' => fn($builder) => $builder->where('status', Reservation::STATUS_ACTIVE)]) ->load(['images', 'tags', 'user']); return OfficeResource::make($office); } public function create(): JsonResource { // $office = DB::transaction(function () use ($office, $attributes) { $office->fill( Arr::except($attributes, ['tags']) )->save(); if (isset($attributes['tags'])) { $office->tags()->attach($attributes['tags']); } return $office; }); Notification::send(User::where('is_admin', true)->get(), new OfficePendingApproval($office)); return OfficeResource::make( $office->load(['images', 'tags', 'user']) ); } // }
-
app/Notifications/OfficePendingApproval.php
Open in GitHubuse App\Models\Office; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; class OfficePendingApproval extends Notification implements ShouldQueue { use Queueable; public function __construct(public Office $office) { // } public function via($notifiable) { return ['mail']; } public function toMail($notifiable) { return (new MailMessage) ->line('The introduction to the notification.') ->action('Notification Action', url('/')) ->line('Thank you for using our application!'); } }