Skip to content
This repository was archived by the owner on Aug 27, 2024. It is now read-only.

Commit 92ac165

Browse files
committed
Remove duplicates of BaseApiController
1 parent 1e9407d commit 92ac165

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

CHANGES

+7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
1.0.3
2+
-----
3+
Add validation to BaseApiController
4+
Remove clones of BaseApiController from related packages
5+
16
1.0.2
7+
-----
28
- Add TransformException
39

410
1.0.1
11+
-----
512
- Fix namespace
613

714
1.0.0

src/Api/BaseApiController.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
namespace Saritasa\Laravel\Controllers\Api;
44

5-
use Saritasa\Transformers\BaseTransformer;
65
use App\Models\User;
6+
use Dingo\Api\Http\Request;
77
use Dingo\Api\Http\Response;
88
use Dingo\Api\Routing\Helpers;
99
use Illuminate\Contracts\Pagination\Paginator;
1010
use Illuminate\Foundation\Validation\ValidatesRequests;
1111
use Illuminate\Routing\Controller;
12+
use Illuminate\Contracts\Validation\Validator;
13+
use Saritasa\DingoApi\Exceptions\ValidationException;
14+
use Saritasa\Transformers\BaseTransformer;
1215
use Saritasa\Transformers\IDataTransformer;
1316

1417
/**
@@ -38,4 +41,14 @@ protected function json($data, IDataTransformer $transformer = null): Response
3841
}
3942
return $this->response->item($data, $t);
4043
}
44+
45+
public function validate(Request $request, array $rules, array $messages = [], array $customAttributes = [])
46+
{
47+
/** @var Validator $validator */
48+
$validator = $this->getValidationFactory()->make($request->all(), $rules, $messages, $customAttributes);
49+
50+
if ($validator->fails()) {
51+
throw new ValidationException($validator->errors());
52+
}
53+
}
4154
}

0 commit comments

Comments
 (0)