mirror of https://github.com/kcal-app/kcal.git
Allow null values for ingredients
This commit is contained in:
parent
d4e3658294
commit
f8c6f81e60
|
|
@ -60,11 +60,11 @@ class RecipeController extends Controller
|
|||
'description' => 'required|string',
|
||||
'servings' => 'required|numeric',
|
||||
'ingredients_amount' => 'required|array',
|
||||
'ingredients_amount.*' => 'required|numeric|min:0',
|
||||
'ingredients_amount.*' => 'required_with:ingredients.*|nullable|numeric|min:0',
|
||||
'ingredients_unit' => 'required|array',
|
||||
'ingredients_unit.*' => 'nullable|string',
|
||||
'ingredients' => 'required|array',
|
||||
'ingredients.*' => 'required|exists:App\Models\Ingredient,id',
|
||||
'ingredients.*' => 'required_with:ingredients_amount.*|nullable|exists:App\Models\Ingredient,id',
|
||||
]);
|
||||
|
||||
$recipe = new Recipe([
|
||||
|
|
@ -79,7 +79,7 @@ class RecipeController extends Controller
|
|||
return;
|
||||
}
|
||||
$ingredient_amounts = [];
|
||||
foreach ($input['ingredients_amount'] as $key => $amount) {
|
||||
foreach (array_filter($input['ingredients_amount']) as $key => $amount) {
|
||||
$ingredient_amounts[$key] = new IngredientAmount([
|
||||
'amount' => (float) $amount,
|
||||
'unit' => $input['ingredients_unit'][$key],
|
||||
|
|
|
|||
|
|
@ -9,17 +9,17 @@ use Illuminate\View\Component;
|
|||
class Select extends Component
|
||||
{
|
||||
public Collection $options;
|
||||
public string $selectedValue;
|
||||
public ?string $selectedValue;
|
||||
|
||||
/**
|
||||
* Select constructor.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $options
|
||||
* @param string $selectedValue
|
||||
* @param ?string $selectedValue
|
||||
*/
|
||||
public function __construct(
|
||||
Collection $options,
|
||||
string $selectedValue = '',
|
||||
?string $selectedValue = '',
|
||||
) {
|
||||
$this->options = $options;
|
||||
$this->selectedValue = $selectedValue;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\View\Components\Inputs;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class Textarea extends Component
|
||||
{
|
||||
public ?string $value;
|
||||
|
||||
/**
|
||||
* Select constructor.
|
||||
*
|
||||
* @param ?string $value
|
||||
*/
|
||||
public function __construct(?string $value = '') {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('components.inputs.textarea')
|
||||
->with('value', $this->value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
{{ $slot }}
|
||||
@foreach ($options as $option)
|
||||
<option value="{{ $option['value'] }}"
|
||||
@if ($option['value'] === $selectedValue) selected @endif>
|
||||
@if ($option['value'] == $selectedValue) selected @endif>
|
||||
{{ $option['label'] }}
|
||||
</option>
|
||||
@endforeach
|
||||
|
|
|
|||
|
|
@ -1,4 +1 @@
|
|||
@props(['disabled' => false])
|
||||
|
||||
<textarea {{ $disabled ? 'disabled' : '' }} {!! $attributes->merge(['class' => 'rounded-md shadow-sm border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50']) !!}>
|
||||
</textarea>
|
||||
<textarea {!! $attributes->merge(['class' => 'rounded-md shadow-sm border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50']) !!}>{{ $value }}</textarea>
|
||||
|
|
|
|||
|
|
@ -70,19 +70,32 @@
|
|||
<div class="flex flex-row space-x-4 mb-4">
|
||||
<x-inputs.input type="number"
|
||||
name="ingredients_amount[]"
|
||||
step="any"
|
||||
required />
|
||||
:value="old('ingredients_amount.' . $i)"
|
||||
step="any" />
|
||||
<x-inputs.select name="ingredients_unit[]"
|
||||
:options="$ingredient_units">
|
||||
:options="$ingredient_units"
|
||||
:selectedValue="old('ingredients_unit.' . $i)">
|
||||
<option value=""></option>
|
||||
</x-inputs.select>
|
||||
<x-inputs.select name="ingredients[]"
|
||||
:options="$ingredients"
|
||||
required>
|
||||
:selectedValue="old('ingredients.' . $i)">
|
||||
<option value=""></option>
|
||||
</x-inputs.select>
|
||||
</div>
|
||||
@endfor
|
||||
|
||||
<!-- Steps -->
|
||||
<h3 class="pt-2 mb-2 font-extrabold">Steps</h3>
|
||||
@for($i = 1; $i < 6; $i++)
|
||||
<div class="flex flex-row space-x-4 mb-4">
|
||||
<div class="text-3xl text-gray-400 text-center">{{ $i }}</div>
|
||||
<x-inputs.textarea class="block mt-1 w-full"
|
||||
name="steps[]"
|
||||
:value="old('steps[$i]')" />
|
||||
</div>
|
||||
@endfor
|
||||
|
||||
<div class="flex items-center justify-end mt-4">
|
||||
<x-inputs.button class="ml-3">
|
||||
{{ __('Add') }}
|
||||
|
|
|
|||
Loading…
Reference in New Issue