Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

themsaid/ergodnc

262 stars
2 code files
View themsaid/ergodnc on GitHub

app/Http/Controllers/OfficeController.php

Open in GitHub
use 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 GitHub
use 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!');
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.