store invoice profile

This commit is contained in:
Peter Papp
2021-04-28 07:32:40 +02:00
parent e7c4048258
commit bcf14595bf
6 changed files with 221 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Http\Controllers\Oasis;
use App\Http\Controllers\Controller;
use App\Http\Resources\Oasis\InvoiceProfileCollection;
use Illuminate\Http\Request;
class InvoiceProfileController extends Controller
{
public function store(Request $request)
{
$profile = \Auth::user()
->invoiceProfile()
->create([
'logo' => store_avatar($request, 'logo') ?? null,
'stamp' => store_avatar($request, 'stamp') ?? null,
'company' => $request->company,
'email' => $request->email,
'ico' => $request->ico,
'dic' => $request->dic,
'ic_dph' => $request->ic_dph,
'registration_notes' => $request->registration_notes,
'author' => $request->author,
'address' => $request->address,
'state' => $request->state,
'city' => $request->city,
'postal_code' => $request->postal_code,
'country' => $request->country,
'phone' => $request->phone,
'bank' => $request->bank,
'iban' => $request->iban,
'swift' => $request->swift,
]);
return response(
new InvoiceProfileCollection($profile), 201
);
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Http\Requests\Oasis;
use Illuminate\Foundation\Http\FormRequest;
class StoreInvoiceProfileRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'logo' => 'sometimes|file',
'stamp' => 'sometimes|file',
'company' => 'required|string',
'email' => 'required|email',
'ico' => 'sometimes|string|nullable',
'dic' => 'sometimes|string|nullable',
'ic_dph' => 'sometimes|string|nullable',
'registration_notes' => 'sometimes|string|nullable',
'author' => 'required|string',
'address' => 'required|string',
'state' => 'required|string',
'city' => 'required|string',
'postal_code' => 'required|string',
'country' => 'required|string',
'phone' => 'required|string',
'bank' => 'required|string',
'iban' => 'required|string',
'swift' => 'required|string',
];
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Http\Resources\Oasis;
use Illuminate\Http\Resources\Json\ResourceCollection;
class InvoiceProfileCollection extends ResourceCollection
{
public $collects = InvoiceProfileResource::class;
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Support\Collection
*/
public function toArray($request)
{
return $this->collection;
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Http\Resources\Oasis;
use Illuminate\Http\Resources\Json\JsonResource;
use Laravel\Cashier\Cashier;
class InvoiceProfileResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'data' => [
'id' => $this->id,
'type' => 'invoice-profile',
'attributes' => [
'logo' => $this->logo,
'stamp' => $this->stamp,
'company' => $this->company,
'email' => $this->email,
'ico' => $this->ico,
'dic' => $this->dic,
'ic_dph' => $this->ic_dph,
'registration_notes' => $this->registration_notes,
'author' => $this->author,
'address' => $this->address,
'state' => $this->state,
'city' => $this->city,
'postal_code' => $this->postal_code,
'country' => $this->country,
'phone' => $this->phone,
'bank' => $this->bank,
'iban' => $this->iban,
'swift' => $this->swift,
],
],
];
}
}