mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Management of links and first form for link storing #616
This commit is contained in:
57
app/Http/Requests/LinkTypeFormRequest.php
Normal file
57
app/Http/Requests/LinkTypeFormRequest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* LinkTypeFormRequest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class BillFormRequest
|
||||
*
|
||||
*
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class LinkTypeFormRequest extends Request
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged and admins
|
||||
return auth()->check() && auth()->user()->hasRole('owner');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
/** @var LinkTypeRepositoryInterface $repository */
|
||||
$repository = app(LinkTypeRepositoryInterface::class);
|
||||
$nameRule = 'required|min:1|unique:link_types,name';
|
||||
$idRule = '';
|
||||
if (!is_null($repository->find($this->integer('id'))->id)) {
|
||||
$idRule = 'exists:link_types,id';
|
||||
$nameRule = 'required|min:1';
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'id' => $idRule,
|
||||
'name' => $nameRule,
|
||||
'inward' => 'required|min:1|different:outward',
|
||||
'outward' => 'required|min:1|different:inward',
|
||||
];
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
@@ -85,7 +85,7 @@ class Request extends FormRequest
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function string(string $field): string
|
||||
public function string(string $field): string
|
||||
{
|
||||
$string = $this->get($field) ?? '';
|
||||
$search = [
|
||||
|
Reference in New Issue
Block a user