forked from eatvio/eatvio-infra
added tests for diets
This commit is contained in:
@@ -2,11 +2,13 @@
|
||||
|
||||
namespace App\Livewire\Diet;
|
||||
|
||||
use App\Models\Diet;
|
||||
use Livewire\Component;
|
||||
use App\Models\Diet; use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
class Edit extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public Diet $diet;
|
||||
|
||||
public $name = '';
|
||||
@@ -35,9 +37,9 @@ class Edit extends Component
|
||||
$this->image = $diet->image;
|
||||
$this->duration = $diet->duration;
|
||||
$this->state = $diet->state;
|
||||
$this->type = json_decode($diet->type, true);
|
||||
$this->type = $diet->type;
|
||||
$this->details = $diet->details;
|
||||
$this->days = json_decode($diet->daily_schedule, true);
|
||||
$this->days = $diet->daily_schedule;
|
||||
}
|
||||
|
||||
public function render()
|
||||
@@ -78,7 +80,7 @@ class Edit extends Component
|
||||
)->to('diet.day-edit');
|
||||
}
|
||||
|
||||
public function publish()
|
||||
public function publish(): void
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
@@ -86,17 +88,18 @@ class Edit extends Component
|
||||
|
||||
$diet->name = $this->name;
|
||||
/* $diet->image = $this->image->store('diets', 'public'); */
|
||||
$diet->image = ! is_string($this->image) ? $this->image->store('plans') : $this->image;
|
||||
$diet->duration = $this->duration;
|
||||
$diet->state = $this->state;
|
||||
$diet->type = json_encode($this->type);
|
||||
$diet->type = $this->type;
|
||||
$diet->details = $this->details;
|
||||
$diet->daily_schedule = json_encode($this->days);
|
||||
$diet->daily_schedule = $this->days;
|
||||
$diet->save();
|
||||
|
||||
$this->redirectRoute('diet.show', $diet);
|
||||
|
||||
/* $user = Auth::user(); */
|
||||
/* $user->author_of_diets()->attach($diet->id); */
|
||||
|
||||
return redirect()->route('diet.show', $diet->id);
|
||||
}
|
||||
|
||||
protected function rules()
|
||||
@@ -105,7 +108,7 @@ class Edit extends Component
|
||||
'name' => 'required|min:3',
|
||||
/* 'image' => 'required|image|max:2048', */
|
||||
'duration' => 'required|numeric|min:7',
|
||||
'state' => 'required|in:draft,active,inactive',
|
||||
'state' => 'required|in:active,draft,archived',
|
||||
'type' => ['required', 'array:meat,veg,corb,alko', 'min:1'],
|
||||
'details' => 'required|min:3',
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user