-
Notifications
You must be signed in to change notification settings - Fork 288
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Seems to be a problem with case-conversion.
Given the contents of the following draft.yaml
:
models:
Certificate:
name: string
certificate_type_id: id
reference: string
document: string
expiry_date: date
remarks: nullable text
CertificateType:
name: string
relationships:
hasMany: Certificate
controllers:
Certificate:
resource: api
CertificateType:
resource: api
Running blueprint:build
will throw the following error:
TypeError: Argument 1 passed to Blueprint\Generators\Statements\ResourceGenerator::visibleColumns() must be an instance of Blueprint\Models\Model, null given, called in /Users/joostjacobs/Code/blueprint/vendor/laravel-shift/blueprint/src/Generators/Statements/ResourceGenerator.php on line 98
A .blueprint
file is not created due to this crash.
It ultimately crashed upon trying to create a Resource in app/Http/Resources/CertificateType.php
.
Examining the partially generated code, the following issues surface:
- In the generated
app/Http/Controllers/CertificateTypeController.php
, we see two imports, one with the correct PascalCase, one with only the first letter capitalized:
<?php
namespace App\Http\Controllers;
use App\CertificateType;
use App\Certificatetype;
- The generated DocBlocks as well as the method body, refer to an incorrectly cased Collection and Resource:
CertificatetypeCollection
should beCertificateTypeCollection
and the Resource respectively should not beCertificatetypeResource
butCertificateTypeResource
.
/**
* @param \Illuminate\Http\Request $request
* @return \App\Http\Resources\CertificatetypeCollection
*/
public function index(Request $request)
{
$certificatetypes = Certificatetype::all();
return new CertificatetypeCollection($certificatetypes);
}
/**
* @param \App\Http\Requests\CertificateTypeStoreRequest $request
* @return \App\Http\Resources\Certificatetype
*/
public function store(CertificateTypeStoreRequest $request)
{
$certificatetype = Certificatetype::create($request->all());
return new CertificatetypeResource($certificatetype);
}
- While the method signatures for
show
,update
, anddestroy
show a correct model binding ofCertificateType $certificateType
, with the variable properly camelCased, the method body uses an all lowercase variable name:
/**
* @param \Illuminate\Http\Request $request
* @param \App\CertificateType $certificateType
* @return \App\Http\Resources\Certificatetype
*/
public function show(Request $request, CertificateType $certificateType)
{
return new CertificatetypeResource($certificatetype);
}
- All the generated
Request
classes for validation are incorrect. They do not feature any of the model's columns, and generates a plain wrong rule instead. I think this is unrelated to the PascalCase problem, but it should be raised as an entirely new issue all together:
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'certificatetype' => 'required',
];
}
I'll raise a separate issue for this.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working