fix: makes portfolio available to form request
This commit is contained in:
@@ -10,6 +10,14 @@ use App\Rules\QuantityValidationRule;
|
|||||||
class TransactionRequest extends FormRequest
|
class TransactionRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
|
||||||
|
protected function prepareForValidation(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->merge([
|
||||||
|
'portfolio' => Portfolio::find($this->requestOrModelValue('portfolio_id', 'transaction'))
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the validation rules that apply to the request.
|
* Get the validation rules that apply to the request.
|
||||||
*
|
*
|
||||||
@@ -17,7 +25,7 @@ class TransactionRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$rules = [
|
$rules = [
|
||||||
'portfolio_id' => ['required', 'exists:portfolios,id'],
|
'portfolio_id' => ['required', 'exists:portfolios,id'],
|
||||||
'symbol' => ['required', 'string', new SymbolValidationRule],
|
'symbol' => ['required', 'string', new SymbolValidationRule],
|
||||||
@@ -28,7 +36,7 @@ class TransactionRequest extends FormRequest
|
|||||||
'numeric',
|
'numeric',
|
||||||
'min:0',
|
'min:0',
|
||||||
new QuantityValidationRule(
|
new QuantityValidationRule(
|
||||||
$this->requestOrModelValue('symbol', 'transaction'),
|
$this->input('portfolio'),
|
||||||
$this->requestOrModelValue('symbol', 'transaction'),
|
$this->requestOrModelValue('symbol', 'transaction'),
|
||||||
$this->requestOrModelValue('transaction_type', 'transaction'),
|
$this->requestOrModelValue('transaction_type', 'transaction'),
|
||||||
$this->requestOrModelValue('date', 'transaction')
|
$this->requestOrModelValue('date', 'transaction')
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ class TransactionsTest extends TestCase
|
|||||||
'cost_basis' => 150,
|
'cost_basis' => 150,
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->postJson(route('api.transaction.store'), $data)
|
$this->actingAs($this->user)
|
||||||
|
->postJson(route('api.transaction.store'), $data)
|
||||||
->assertCreated()
|
->assertCreated()
|
||||||
->assertJsonStructure([
|
->assertJsonStructure([
|
||||||
'id',
|
'id',
|
||||||
|
|||||||
Reference in New Issue
Block a user