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

63 lines
1.5 KiB
PHP
Raw Normal View History

2020-09-23 02:46:35 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
2020-09-23 02:46:35 +02:00
namespace App\Http\Requests\Expense;
2020-11-25 15:19:52 +01:00
use App\Http\Requests\Request;
2023-11-03 01:07:05 +01:00
use Illuminate\Validation\Rule;
2020-09-23 02:46:35 +02:00
class BulkExpenseRequest extends Request
2020-09-23 02:46:35 +02:00
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
2023-11-03 01:07:05 +01:00
return true;
2020-09-23 02:46:35 +02:00
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
2023-11-03 01:07:05 +01:00
/** @var \App\Models\User $user */
$user = auth()->user();
return [
'ids' => ['required','bail','array', Rule::exists('expenses', 'id')->where('company_id', $user->company()->id)],
'category_id' => ['sometimes', 'bail', Rule::exists('expense_categories', 'id')->where('company_id', $user->company()->id)],
'action' => 'in:archive,restore,delete,bulk_categorize',
];
}
public function prepareForValidation()
{
$input = $this->all();
if (isset($input['ids'])) {
$input['ids'] = $this->transformKeys($input['ids']);
}
2020-09-23 02:46:35 +02:00
2023-11-03 01:07:05 +01:00
if (isset($input['category_id'])) {
$input['category_id'] = $this->transformKeys($input['category_id']);
2020-09-23 02:46:35 +02:00
}
2023-11-03 01:07:05 +01:00
$this->replace($input);
2020-09-23 02:46:35 +02:00
}
}