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
1 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\Models\User;
use App\Models\Validators\OfficeValidator;
use Illuminate\Http\Resources\Json\JsonResource;
use App\Notifications\OfficePendingApproval;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Notification;
 
class OfficeController extends Controller
{
//
public function create(): JsonResource
{
abort_unless(auth()->user()->tokenCan('office.create'),
Response::HTTP_FORBIDDEN
);
 
$attributes = (new OfficeValidator())->validate(
$office = new Office(),
request()->all()
);
 
$attributes['approval_status'] = Office::APPROVAL_PENDING;
$attributes['user_id'] = auth()->id();
 
$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'])
);
}
//
}

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.