mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 17:24:10 +00:00
CompanyRequest::getCompanyPayload() accepted 'slug' from the client but never generated it, so the installation wizard (which PUTs /api/v1/company) left the slug empty when setting up the first company. Match the sibling CompaniesRequest (which already does Str::slug($this->name)) and generate the slug from the name server-side; drop the now-unused 'slug' validation rule.
Fixes the same bug that master's ed7af3fc tried to fix client-side with a lodash deburr + regex workaround in Step7CompanyInfo.vue. v3.0's installation wizard is a rewrite under resources/scripts/features/installation/CompanyView.vue and doesn't carry that workaround, so the cleaner fix is to make the backend authoritative like CompaniesRequest already is.
55 lines
1.2 KiB
PHP
55 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class CompanyRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => [
|
|
'required',
|
|
Rule::unique('companies')->ignore($this->header('company'), 'id'),
|
|
],
|
|
'vat_id' => [
|
|
'nullable',
|
|
],
|
|
'tax_id' => [
|
|
'nullable',
|
|
],
|
|
'address.country_id' => [
|
|
'required',
|
|
],
|
|
];
|
|
}
|
|
|
|
public function getCompanyPayload()
|
|
{
|
|
return collect($this->validated())
|
|
->only([
|
|
'name',
|
|
'vat_id',
|
|
'tax_id',
|
|
])
|
|
->merge([
|
|
'slug' => Str::slug($this->name),
|
|
])
|
|
->toArray();
|
|
}
|
|
}
|