1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 23:22:52 +01:00
invoiceninja/app/Http/Requests/ProposalSnippetRequest.php

40 lines
1.1 KiB
PHP
Raw Normal View History

2018-01-30 19:58:55 +01:00
<?php
namespace App\Http\Requests;
2018-02-08 12:01:51 +01:00
use App\Models\ProposalCategory;
2018-01-30 19:58:55 +01:00
class ProposalSnippetRequest extends EntityRequest
{
protected $entityType = ENTITY_PROPOSAL_SNIPPET;
2018-02-08 12:01:51 +01:00
public function sanitize()
{
$input = $this->all();
// check if we're creating a new proposal category
if ($this->proposal_category_id == '-1') {
$data = [
'name' => trim($this->proposal_category_name)
];
if (ProposalCategory::validate($data) === true) {
$category = app('App\Ninja\Repositories\ProposalCategoryRepository')->save($data);
$input['proposal_category_id'] = $category->id;
} else {
$input['proposal_category_id'] = null;
}
} elseif ($this->proposal_category_id) {
$input['proposal_category_id'] = ProposalCategory::getPrivateId($this->proposal_category_id);
}
$this->replace($input);
return $this->all();
}
2019-01-30 12:00:26 +01:00
public function authorize()
{
return $this->user()->can('view', ENTITY_PROPOSAL) || $this->user()->can('createEntity', ENTITY_PROPOSAL);
}
2018-01-30 19:58:55 +01:00
}