forked from eatvio/eatvio-infra
WIP recipe
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Livewire\Recipe;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Livewire\Attributes\On;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\Tag;
|
||||
use App\Models\Recipe;
|
||||
@@ -14,16 +15,19 @@ class Create extends Component
|
||||
|
||||
public $image;
|
||||
public $state = 'active';
|
||||
public $tags;
|
||||
public $tags = [];
|
||||
public $title;
|
||||
public $type = 'other';
|
||||
public $video_url = '';
|
||||
public $cooking_time = '10';
|
||||
public $description = "";
|
||||
public $steps = [['image' => '', 'description' => '']];
|
||||
public $ingredients = [['name' => '', 'portion' => '', 'unit' => '']];
|
||||
public $ingredients = [];
|
||||
public $ingredients_name = "";
|
||||
public $ingredients_portion = "";
|
||||
public $ingredients_unit = "gr";
|
||||
|
||||
protected $listeners = ['stepRemoved' => '$refresh', 'parentComponentTagAdded', 'parentComponentTagRemoved'];
|
||||
protected $listeners = ['stepRemoved' => '$refresh'];
|
||||
|
||||
protected function rules()
|
||||
{
|
||||
@@ -45,9 +49,19 @@ class Create extends Component
|
||||
return view('livewire.recipe.create');
|
||||
}
|
||||
|
||||
public function addIngredient()
|
||||
public function addIngredient(): void
|
||||
{
|
||||
$this->ingredients[] = ['name' => '', 'portion' => ''];
|
||||
// dd(
|
||||
// $this->ingredients_name,
|
||||
// $this->ingredients_portion,
|
||||
// $this->ingredients_unit
|
||||
// );
|
||||
$this->ingredients[] = [
|
||||
'name' => $this->ingredients_name,
|
||||
'portion' => $this->ingredients_portion,
|
||||
'unit' => $this->ingredients_unit
|
||||
];
|
||||
$this->reset('ingredients_name', 'ingredients_portion', 'ingredients_unit');
|
||||
}
|
||||
|
||||
public function removeIngredient($i)
|
||||
@@ -77,12 +91,14 @@ class Create extends Component
|
||||
$this->dispatch('stepRemoved')->self();
|
||||
}
|
||||
|
||||
#[On('parentComponentTagAdded')]
|
||||
public function parentComponentTagAdded(Tag $tag)
|
||||
{
|
||||
$tagIndex = $tag->id;
|
||||
$this->tags[$tagIndex] = $tag;
|
||||
}
|
||||
|
||||
#[On('parentComponentTagRemoved')]
|
||||
public function parentComponentTagRemoved($tag)
|
||||
{
|
||||
$this->tags = collect($this->tags)
|
||||
@@ -124,6 +140,7 @@ class Create extends Component
|
||||
|
||||
public function publish()
|
||||
{
|
||||
// dd($this->description);
|
||||
$this->validate();
|
||||
|
||||
$recipe = new Recipe();
|
||||
@@ -146,4 +163,9 @@ class Create extends Component
|
||||
|
||||
return redirect()->route('recipe.show', $recipe->id);
|
||||
}
|
||||
|
||||
// public function updated($property)
|
||||
// {
|
||||
// dd($property, $this->$property);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -63,7 +63,13 @@ class Edit extends Component
|
||||
|
||||
public function addIngredient()
|
||||
{
|
||||
$this->ingredients[] = ['name' => '', 'portion' => ''];
|
||||
// $this->ingredients[] = ['name' => '', 'portion' => ''];
|
||||
$this->ingredients[] = [
|
||||
'name' => $this->ingredients_name,
|
||||
'portion' => $this->ingredients_portion,
|
||||
'unit' => $this->ingredients_unit
|
||||
];
|
||||
$this->reset('ingredients_name', 'ingredients_portion', 'ingredients_unit');
|
||||
}
|
||||
|
||||
public function removeIngredient($i)
|
||||
@@ -135,6 +141,7 @@ class Edit extends Component
|
||||
|
||||
public function publish()
|
||||
{
|
||||
dd($this->steps);
|
||||
$this->validate();
|
||||
|
||||
$recipe = $this->recipe;
|
||||
|
||||
Reference in New Issue
Block a user