forked from eatvio/eatvio-infra
meeting the requirements of a static analyzer
This commit is contained in:
@@ -5,17 +5,21 @@ namespace App\Livewire\Diet;
|
||||
use App\Models\Diet;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
class Edit extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public Diet $diet;
|
||||
|
||||
public string $name = '';
|
||||
|
||||
public string $image;
|
||||
public UploadedFile|string $image = '';
|
||||
|
||||
public int $duration = 7;
|
||||
public int|string $duration = '7';
|
||||
|
||||
public string $state = 'draft';
|
||||
|
||||
@@ -25,24 +29,19 @@ class Edit extends Component
|
||||
|
||||
public array $days = [];
|
||||
|
||||
public int $copyedDay;
|
||||
public string $copyedDay;
|
||||
|
||||
public array $copyedDayData;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $listeners = ['dayUpdated', 'makeCopy', 'makePaste'];
|
||||
|
||||
public function mount(Diet $diet): void
|
||||
{
|
||||
$this->name = $diet->name;
|
||||
$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(): View|ViewFactory
|
||||
@@ -50,7 +49,7 @@ class Edit extends Component
|
||||
return view('livewire.diet.edit');
|
||||
}
|
||||
|
||||
public function dayUpdated(int $dayIndex, array $data): void
|
||||
public function dayUpdated(string $dayIndex, array $data): void
|
||||
{
|
||||
$this->days[$dayIndex] = $data;
|
||||
}
|
||||
@@ -67,13 +66,13 @@ class Edit extends Component
|
||||
$this->publish();
|
||||
}
|
||||
|
||||
public function makeCopy(int $day): void
|
||||
public function makeCopy(string $day): void
|
||||
{
|
||||
/* dd($day); */
|
||||
$this->copyedDay = $day;
|
||||
}
|
||||
|
||||
public function makePaste(int $copyToDay): void
|
||||
public function makePaste(string $copyToDay): void
|
||||
{
|
||||
$data = $this->days[$this->copyedDay];
|
||||
$this->dispatch(
|
||||
@@ -91,19 +90,20 @@ class Edit extends Component
|
||||
|
||||
$diet->name = $this->name;
|
||||
/* $diet->image = $this->image->store('diets', 'public'); */
|
||||
$diet->image = ! is_string($this->image) ? $this->image->store('diets') : $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();
|
||||
|
||||
/* $user = Auth::user(); */
|
||||
/* $user->author_of_diets()->attach($diet->id); */
|
||||
$this->redirectRoute('diet.show', $diet);
|
||||
}
|
||||
|
||||
// return redirect()->route('diet.show', $diet->id);
|
||||
|
||||
$this->redirectRoute('diet.show', $diet->id);
|
||||
protected function getListeners(): array
|
||||
{
|
||||
return ['dayUpdated', 'makeCopy', 'makePaste'];
|
||||
}
|
||||
|
||||
protected function rules(): array
|
||||
@@ -112,7 +112,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