use NurbekJummayev\ApiResponseHelper\Exceptions\NotFoundException;
use NurbekJummayev\ApiResponseHelper\Exceptions\ForbiddenException;
use NurbekJummayev\ApiResponseHelper\Exceptions\ValidationException;
// Not Found Exception
public function show(int $id)
{
$model = Product::find($id);
if (!$model) {
throw new NotFoundException('Product not found', ['product_id' => $id]);
}
return okResponse($model);
}
// Validation Exception
public function store(Request $request)
{
$validator = Validator::make($request->all(), $rules);
if ($validator->fails()) {
throw new ValidationException(
message: 'Validation failed',
data: ['errors' => $validator->errors()]
);
}
$model = Product::create($request->all());
return createdResponse($model);
}
// Forbidden Exception
public function update(Request $request, int $id)
{
$model = Product::findOrFail($id);
if (!auth()->user()->can('update', $model)) {
throw new ForbiddenException('You cannot update this product');
}
$model->update($request->all());
return okResponse($model);
}
> use NurbekJummayev\ApiResponseHelper\Exceptions\ValidationException as ApiValidationException;
>
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.