mirror of
https://github.com/ambieco/scribe.git
synced 2026-04-29 11:26:04 +08:00
Allow use @apiResource without @apiResourceModel
This commit is contained in:
@@ -17,13 +17,17 @@ trait InstantiatesExampleModels
|
||||
* @param string[] $relations
|
||||
* @param \ReflectionFunctionAbstract|null $transformationMethod A method which has the model as its first parameter. Useful if the `$type` is empty.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model|object
|
||||
* @return \Illuminate\Database\Eloquent\Model|object|null
|
||||
*/
|
||||
protected function instantiateExampleModel(
|
||||
?string $type = null, array $factoryStates = [],
|
||||
array $relations = [], ?ReflectionFunctionAbstract $transformationMethod = null
|
||||
)
|
||||
{
|
||||
// Early return if JsonResource working with empty resource, there won't have an example model
|
||||
if($type == null && $transformationMethod == null)
|
||||
return null;
|
||||
|
||||
if ($type == null) {
|
||||
$parameter = Arr::first($transformationMethod->getParameters());
|
||||
if ($parameter->hasType() && !$parameter->getType()->isBuiltin() && class_exists($parameter->getType()->getName())) {
|
||||
|
||||
@@ -11,6 +11,7 @@ use Knuckles\Scribe\Extracting\RouteDocBlocker;
|
||||
use Knuckles\Scribe\Extracting\Shared\ApiResourceResponseTools;
|
||||
use Knuckles\Scribe\Extracting\Strategies\Strategy;
|
||||
use Knuckles\Scribe\Tools\AnnotationParser as a;
|
||||
use Knuckles\Scribe\Tools\ConsoleOutputUtils as c;
|
||||
use Knuckles\Scribe\Tools\Utils;
|
||||
use Mpociot\Reflection\DocBlock\Tag;
|
||||
|
||||
@@ -101,7 +102,7 @@ class UseApiResourceTags extends Strategy
|
||||
}
|
||||
|
||||
if (empty($modelClass)) {
|
||||
throw new Exception("Couldn't detect an Eloquent API resource model from your docblock. Did you remember to specify a model using @apiResourceModel?");
|
||||
c::warn("Couldn't detect an Eloquent API resource model from your docblock. Did you remember to specify a model using @apiResourceModel?");
|
||||
}
|
||||
|
||||
return [$modelClass, $states, $relations, $pagination];
|
||||
|
||||
Reference in New Issue
Block a user