mirror of https://github.com/kcal-app/kcal.git
Handle recipe ingredient separators in recipe show
This commit is contained in:
parent
8288a73faa
commit
5463b53478
|
|
@ -10,6 +10,7 @@ use ElasticScoutDriverPlus\QueryDsl;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Laravel\Scout\Searchable;
|
use Laravel\Scout\Searchable;
|
||||||
use Spatie\Image\Manipulations;
|
use Spatie\Image\Manipulations;
|
||||||
use Spatie\MediaLibrary\HasMedia;
|
use Spatie\MediaLibrary\HasMedia;
|
||||||
|
|
@ -73,6 +74,7 @@ use Spatie\Tags\HasTags;
|
||||||
* @property-read int|null $ingredient_separators_count
|
* @property-read int|null $ingredient_separators_count
|
||||||
* @method static \Database\Factories\RecipeFactory factory(...$parameters)
|
* @method static \Database\Factories\RecipeFactory factory(...$parameters)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Recipe whereTimeCook($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Recipe whereTimeCook($value)
|
||||||
|
* @property-read Collection $ingredients_list
|
||||||
*/
|
*/
|
||||||
final class Recipe extends Model implements HasMedia
|
final class Recipe extends Model implements HasMedia
|
||||||
{
|
{
|
||||||
|
|
@ -162,6 +164,16 @@ final class Recipe extends Model implements HasMedia
|
||||||
return round($this->weight / $this->servings, 2);
|
return round($this->weight / $this->servings, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the ingredients list (ingredient amounts and separators).
|
||||||
|
*/
|
||||||
|
public function getIngredientsListAttribute(): Collection {
|
||||||
|
return new Collection([
|
||||||
|
...$this->ingredientAmounts,
|
||||||
|
...$this->ingredientSeparators,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the steps for this Recipe.
|
* Get the steps for this Recipe.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -52,23 +52,34 @@
|
||||||
</h1>
|
</h1>
|
||||||
<div class="prose prose-lg">
|
<div class="prose prose-lg">
|
||||||
<ul class="space-y-2">
|
<ul class="space-y-2">
|
||||||
@foreach($recipe->ingredientAmounts as $ia)
|
@foreach($recipe->ingredientsList->sortBy('weight') as $item)
|
||||||
<li>
|
@if($item::class === \App\Models\IngredientAmount::class)
|
||||||
<span>
|
<li>
|
||||||
{{ \App\Support\Number::fractionStringFromFloat($ia->amount) }}
|
<span>
|
||||||
@if($ia->unitFormatted){{ $ia->unitFormatted }}@endif
|
{{ \App\Support\Number::fractionStringFromFloat($item->amount) }}
|
||||||
@if($ia->ingredient->type === \App\Models\Recipe::class)
|
@if($item->unitFormatted){{ $item->unitFormatted }}@endif
|
||||||
<a class="text-gray-500 hover:text-gray-700 hover:border-gray-300"
|
@if($item->ingredient->type === \App\Models\Recipe::class)
|
||||||
href="{{ route('recipes.show', $ia->ingredient) }}">
|
<a class="text-gray-500 hover:text-gray-700 hover:border-gray-300"
|
||||||
{{ $ia->ingredient->name }}
|
href="{{ route('recipes.show', $item->ingredient) }}">
|
||||||
</a>
|
{{ $item->ingredient->name }}
|
||||||
@else
|
</a>
|
||||||
{{ $ia->ingredient->name }}@if($ia->ingredient->detail), {{ $ia->ingredient->detail }}@endif
|
@else
|
||||||
@endif
|
{{ $item->ingredient->name }}@if($item->ingredient->detail), {{ $item->ingredient->detail }}@endif
|
||||||
@if($ia->detail)<span class="text-gray-500">{{ $ia->detail }}</span>@endif
|
@endif
|
||||||
<div x-show="showNutrientsSummary" class="text-sm text-gray-500">{{ $ia->nutrients_summary }}</div>
|
@if($item->detail)<span class="text-gray-500">{{ $item->detail }}</span>@endif
|
||||||
</span>
|
<div x-show="showNutrientsSummary" class="text-sm text-gray-500">{{ $item->nutrients_summary }}</div>
|
||||||
</li>
|
</span>
|
||||||
|
</li>
|
||||||
|
@elseif($item::class === \App\Models\RecipeSeparator::class)
|
||||||
|
</ul></div>
|
||||||
|
@if($item->text)
|
||||||
|
<h2 class="mt-3 font-bold">{{ $item->text }}</h2>
|
||||||
|
@else
|
||||||
|
<hr class="mt-3 lg:w-1/2" />
|
||||||
|
@endif
|
||||||
|
<div class="prose prose-lg">
|
||||||
|
<ul class="space-y-2">
|
||||||
|
@endif
|
||||||
@endforeach
|
@endforeach
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue