1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Http/Requests/Project/StoreProjectRequest.php

64 lines
1.5 KiB
PHP
Raw Normal View History

2020-10-08 00:25:39 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-10-08 00:25:39 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Project;
use App\Http\Requests\Request;
2020-10-20 01:55:14 +02:00
use App\Models\Client;
2020-10-08 00:25:39 +02:00
use App\Models\Project;
use App\Utils\Traits\MakesHash;
2020-12-11 21:51:10 +01:00
use Illuminate\Validation\Rule;
2020-10-08 00:25:39 +02:00
class StoreProjectRequest extends Request
{
use MakesHash;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('create', Project::class);
}
public function rules()
{
$rules = [];
2020-11-25 15:19:52 +01:00
$rules['name'] = 'required';
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
2020-12-11 21:51:10 +01:00
if (isset($this->number)) {
$rules['number'] = Rule::unique('projects')->where('company_id', auth()->user()->company()->id);
}
2020-10-08 00:25:39 +02:00
return $this->globalRules($rules);
2020-10-08 00:25:39 +02:00
}
protected function prepareForValidation()
{
2020-11-25 15:19:52 +01:00
$input = $this->decodePrimaryKeys($this->all());
2020-10-08 00:25:39 +02:00
2021-01-07 23:25:00 +01:00
if(array_key_exists('color', $input) && is_null($input['color']))
$input['color'] = '#fff';
2020-10-08 00:25:39 +02:00
$this->replace($input);
}
2020-10-20 01:55:14 +02:00
public function getClient($client_id)
{
return Client::find($client_id);
}
2020-10-08 00:25:39 +02:00
}