forked from eatvio/eatvio-infra
meeting the requirements of a static analyzer
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Actions\Fortify;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
|
||||
@@ -13,7 +14,7 @@ class UpdateUserProfileInformation implements UpdatesUserProfileInformation
|
||||
/**
|
||||
* Validate and update the given user's profile information.
|
||||
*
|
||||
* @param array<string, string> $input
|
||||
* @param array<string|UploadedFile> $input
|
||||
*/
|
||||
public function update(User $user, array $input): void
|
||||
{
|
||||
|
||||
@@ -12,15 +12,9 @@ class DietSelected
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @var Diet
|
||||
*/
|
||||
public $diet;
|
||||
public Diet $diet;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $user;
|
||||
public User $user;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
|
||||
@@ -12,23 +12,20 @@ use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
|
||||
class CalendarController extends Controller
|
||||
{
|
||||
public string|int|null $weekStartsAt;
|
||||
public int $weekStartsAt;
|
||||
|
||||
public string|int|null $weekEndsAt;
|
||||
public int $weekEndsAt;
|
||||
|
||||
public Carbon $startsAt;
|
||||
|
||||
public Carbon $endsAt;
|
||||
|
||||
public string|int|null $gridStartsAt;
|
||||
public Carbon $gridStartsAt;
|
||||
|
||||
public string|int|null $gridEndsAt;
|
||||
public Carbon $gridEndsAt;
|
||||
|
||||
public function __construct(
|
||||
string|int|null $initialYear = null,
|
||||
string|int|null $initialMonth = null,
|
||||
string|int|null $weekStartsAt = null
|
||||
) {
|
||||
public function __construct(?int $initialYear = null, ?int $initialMonth = null, ?int $weekStartsAt = null)
|
||||
{
|
||||
$this->weekStartsAt = $weekStartsAt ?? Carbon::MONDAY;
|
||||
$this->weekEndsAt = $this->weekStartsAt === Carbon::MONDAY
|
||||
? Carbon::SUNDAY
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\ChatMessageUpdated;
|
||||
use App\Messages\ChatMessage;
|
||||
use App\Models\Chat;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
@@ -45,18 +43,6 @@ class ChatController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* public function create(): void
|
||||
{
|
||||
ChatMessageUpdated::dispatch(
|
||||
new ChatMessage(
|
||||
time(),
|
||||
'some text '.md5(' '.time())
|
||||
)
|
||||
);
|
||||
}
|
||||
*/
|
||||
|
||||
public function show(int $lastChatUser): View|ViewFactory
|
||||
{
|
||||
$lastChatUser = User::find($lastChatUser);
|
||||
@@ -85,7 +71,7 @@ class ChatController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
private function makeChanName(int $from, int $to): string
|
||||
private function makeChanName(?int $from = null, ?int $to = null): string
|
||||
{
|
||||
return (int) $from < (int) $to
|
||||
? $from.'_'.$to
|
||||
|
||||
@@ -8,7 +8,6 @@ use Illuminate\Contracts\View\View;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
|
||||
public function show(User $user): View|ViewFactory
|
||||
{
|
||||
return view('user.show', ['user' => $user]);
|
||||
|
||||
@@ -12,17 +12,9 @@ class ProcessDietSelectedNotification implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $afterCommit = true;
|
||||
public bool $afterCommit = true;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(DietSelected $event)
|
||||
public function handle(DietSelected $event): void
|
||||
{
|
||||
$user = $event->user;
|
||||
$diet = $event->diet;
|
||||
|
||||
@@ -4,16 +4,14 @@ namespace App\Livewire\Chat;
|
||||
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Collection;
|
||||
use Livewire\Component;
|
||||
|
||||
class LastUsers extends Component
|
||||
{
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
public $lastChatUsers;
|
||||
public Collection $lastChatUsers;
|
||||
|
||||
public int $activeUserId;
|
||||
public ?int $activeUserId = null;
|
||||
|
||||
public int $curUserId;
|
||||
|
||||
|
||||
@@ -12,15 +12,15 @@ use Livewire\Component;
|
||||
|
||||
class MessageWindow extends Component
|
||||
{
|
||||
public Collection $messages;
|
||||
public array|Collection $messages = [];
|
||||
|
||||
public string $curMessage = '';
|
||||
|
||||
public int $curUserId;
|
||||
|
||||
public int $recipientUserId;
|
||||
public ?int $recipientUserId = null;
|
||||
|
||||
public User $recipientUser;
|
||||
public ?User $recipientUser = null;
|
||||
|
||||
public string $chanId;
|
||||
|
||||
@@ -61,7 +61,7 @@ class MessageWindow extends Component
|
||||
}
|
||||
|
||||
// FIXME
|
||||
public function mount(?int $recipientUserId): void
|
||||
public function mount(?int $recipientUserId = null): void
|
||||
{
|
||||
$this->recipientUserId = $recipientUserId;
|
||||
$this->recipientUser = User::find($recipientUserId);
|
||||
|
||||
@@ -2,27 +2,17 @@
|
||||
|
||||
namespace App\Livewire\Chat;
|
||||
|
||||
use Livewire\Component;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Tracker extends Component
|
||||
{
|
||||
public bool $showNewMessageNotifycation = false;
|
||||
public int|bool $showNewMessageNotifycation = false;
|
||||
|
||||
public array $myMessages = [];
|
||||
|
||||
// Special Syntax: ['echo:{channel},{event}' => '{method}']
|
||||
/**
|
||||
* some Listeners
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* */
|
||||
protected $listeners = ['echo:direct-chat,ChatMessageUpdated' => 'notifyNewMessage'];
|
||||
|
||||
public function notifyNewMessage(mixed $payload): void
|
||||
public function notifyNewMessage(string $payload): void
|
||||
{
|
||||
$this->myMessages[] = $payload;
|
||||
$this->showNewMessageNotifycation = true;
|
||||
@@ -32,4 +22,9 @@ class Tracker extends Component
|
||||
{
|
||||
return view('livewire.chat.tracker');
|
||||
}
|
||||
|
||||
protected function getListeners(): array
|
||||
{
|
||||
return ['echo:direct-chat,ChatMessageUpdated' => 'notifyNewMessage'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ use App\Models\ConsultantEducation;
|
||||
use App\Models\User;
|
||||
use App\Models\UserAttachment;
|
||||
use App\Notifications\ConsultantRequestStarted;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class RegistrationForm extends Component
|
||||
{
|
||||
@@ -30,16 +30,15 @@ class RegistrationForm extends Component
|
||||
|
||||
public string $telegramLink = '';
|
||||
|
||||
public int $hasMedicalEducation = 0;
|
||||
public bool|int $hasMedicalEducation = false;
|
||||
|
||||
public Collection $certPhotos;
|
||||
public array|Collection $certPhotos = [];
|
||||
|
||||
public array $tmpCertPhotos = [];
|
||||
|
||||
public string $legalType = 'selfemployed';
|
||||
|
||||
/** @phpstan-ignore-next-line */
|
||||
protected $rules = [
|
||||
protected array $rules = [
|
||||
'medicalEducations.*.title' => 'required|string|min:6',
|
||||
'medicalEducations.*.date' => 'required|date',
|
||||
'vkLink' => 'required|url',
|
||||
@@ -65,9 +64,9 @@ class RegistrationForm extends Component
|
||||
|
||||
$photos = $this->user->attachments()->certs()->get();
|
||||
|
||||
if (count($photos) > 0) {
|
||||
$this->certPhotos = collect($photos);
|
||||
}
|
||||
// if ($photos) {
|
||||
$this->certPhotos = collect($photos);
|
||||
// }
|
||||
}
|
||||
|
||||
public function render(): View|ViewFactory
|
||||
@@ -95,7 +94,7 @@ class RegistrationForm extends Component
|
||||
$this->medicalEducations = $medicalEducations;
|
||||
}
|
||||
|
||||
public function remove(int $index): void
|
||||
public function remove(string $index): void
|
||||
{
|
||||
$filteredEducations = array_filter(
|
||||
$this->medicalEducations,
|
||||
@@ -146,7 +145,7 @@ class RegistrationForm extends Component
|
||||
$newFile = UserAttachment::updateOrCreate(
|
||||
$fileData,
|
||||
[
|
||||
'path' => preg_replace("/public\//xi", '/storage/', $curCert),
|
||||
'path' => preg_replace('/public\//xi', '/storage/', $curCert),
|
||||
'specs' => json_encode(
|
||||
[
|
||||
'ext' => $photo->extension(),
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
namespace App\Livewire\Diary;
|
||||
|
||||
use App\Models\ConsultantDiaryComment;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
use App\Models\Diary;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use App\Models\Diary;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
|
||||
class ConsultantCommentsEdit extends Component
|
||||
{
|
||||
@@ -16,9 +16,9 @@ class ConsultantCommentsEdit extends Component
|
||||
|
||||
public Diary $diary;
|
||||
|
||||
public Collection $curMeals;
|
||||
public array|Collection $curMeals = [];
|
||||
|
||||
public Collection $typeNames;
|
||||
public array $typeNames;
|
||||
|
||||
public array $comments = [];
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ namespace App\Livewire\Diary;
|
||||
|
||||
use App\Models\Meal;
|
||||
use App\Models\UserAttachment;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class MealPhotos extends Component
|
||||
{
|
||||
@@ -18,7 +18,7 @@ class MealPhotos extends Component
|
||||
|
||||
public array $tmpMealPhotos = [];
|
||||
|
||||
public function render():View|ViewFactory
|
||||
public function render(): View|ViewFactory
|
||||
{
|
||||
return view(
|
||||
'livewire.diary.meal-photos',
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace App\Livewire\Diet\Comment;
|
||||
use App\Models\Diet;
|
||||
use App\Models\DietComment;
|
||||
use App\Models\User;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class Create extends Component
|
||||
{
|
||||
@@ -17,7 +17,7 @@ class Create extends Component
|
||||
|
||||
public string $body = '';
|
||||
|
||||
public int $grade = 0;
|
||||
public string|int $grade = 0;
|
||||
|
||||
public bool $isChecked = true;
|
||||
|
||||
|
||||
@@ -11,13 +11,13 @@ class Show extends Component
|
||||
{
|
||||
public Diet $diet;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $listeners = ['commentAdded' => '$refresh'];
|
||||
|
||||
public function render(): View|ViewFactory
|
||||
{
|
||||
return view('livewire.diet.comment.show');
|
||||
}
|
||||
|
||||
protected function getListeners(): array
|
||||
{
|
||||
return ['commentAdded' => '$refresh'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace App\Livewire\Diet\Comment;
|
||||
|
||||
use App\Models\DietComment;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class Upvote extends Component
|
||||
{
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
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 Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class Create extends Component
|
||||
{
|
||||
@@ -15,9 +16,9 @@ class Create extends Component
|
||||
|
||||
public string $name = '';
|
||||
|
||||
public string $image;
|
||||
public ?UploadedFile $image = null;
|
||||
|
||||
public int $duration = 7;
|
||||
public int|string $duration = '7';
|
||||
|
||||
public string $state = 'draft';
|
||||
|
||||
@@ -27,19 +28,16 @@ class Create extends Component
|
||||
|
||||
public array $days = [];
|
||||
|
||||
public int $copyedDay;
|
||||
public string $copyedDay;
|
||||
|
||||
public array $copyedDayData;
|
||||
|
||||
/** @phpstan-ignore-next-line */
|
||||
protected $listeners = ['dayUpdated', 'makeCopy', 'makePaste'];
|
||||
|
||||
public function render(): View|ViewFactory
|
||||
{
|
||||
return view('livewire.diet.create');
|
||||
}
|
||||
|
||||
public function dayUpdated(int $dayIndex, array $data): void
|
||||
public function dayUpdated(string $dayIndex, array $data): void
|
||||
{
|
||||
$this->days[$dayIndex] = $data;
|
||||
}
|
||||
@@ -56,12 +54,12 @@ class Create extends Component
|
||||
$this->publish();
|
||||
}
|
||||
|
||||
public function makeCopy(int $day):void
|
||||
public function makeCopy(string $day): void
|
||||
{
|
||||
$this->copyedDay = $day;
|
||||
}
|
||||
|
||||
public function makePaste(int $copyToDay): void
|
||||
public function makePaste(string $copyToDay): void
|
||||
{
|
||||
$data = $this->days[$this->copyedDay];
|
||||
$this->dispatch('takePaste', day: $copyToDay, data: $data)->to('diet.day-edit');
|
||||
@@ -73,21 +71,24 @@ class Create extends Component
|
||||
|
||||
$diet = new Diet();
|
||||
$diet->name = $this->name;
|
||||
/** @phpstan-ignore-next-line */
|
||||
$diet->image = $this->image->store('diets', 'public');
|
||||
// $diet->image = $this->image->store('diets', 'public');
|
||||
$diet->image = $this->image->store('diets');
|
||||
$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->save();
|
||||
$diet->daily_schedule = $this->days;
|
||||
$diet->saveOrFail();
|
||||
|
||||
$user = Auth::user();
|
||||
$user->author_of_diets()->attach($diet->id);
|
||||
|
||||
// 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
|
||||
@@ -96,7 +97,7 @@ class Create 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',
|
||||
];
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
namespace App\Livewire\Diet;
|
||||
|
||||
use Livewire\Component;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class DayEdit extends Component
|
||||
{
|
||||
public int $day;
|
||||
public string $day;
|
||||
|
||||
public array $eatingTypes = ['breakfast', 'dinner', 'supper', 'lunch', 'snacks'];
|
||||
|
||||
@@ -22,11 +22,7 @@ class DayEdit extends Component
|
||||
|
||||
public string $portion = 'gram';
|
||||
|
||||
/** @phpstan-ignore-next-line */
|
||||
protected $listeners = ['takePaste'];
|
||||
|
||||
/** @phpstan-ignore-next-line */
|
||||
protected $rules = [
|
||||
protected array $rules = [
|
||||
'name' => 'required|min:3',
|
||||
'quantity' => 'required|numeric|min:1',
|
||||
'portion' => 'required|min:3',
|
||||
@@ -84,7 +80,7 @@ class DayEdit extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function takePaste(int $day, array $data): void
|
||||
public function takePaste(string $day, array $data): void
|
||||
{
|
||||
if (intval($day) === intval($this->day)) {
|
||||
foreach ($data as $type => $props) {
|
||||
@@ -93,4 +89,9 @@ class DayEdit extends Component
|
||||
$this->dispatch('dayUpdated', dayIndex: $this->day, data: $this->portions);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getListeners(): array
|
||||
{
|
||||
return ['takePaste'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
];
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace App\Livewire\Diet;
|
||||
|
||||
use App\Models\Diet;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class Like extends Component
|
||||
{
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace App\Livewire\Diet;
|
||||
use App\Events\DietSelected;
|
||||
use App\Models\Diet;
|
||||
use App\Models\User;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class StartButton extends Component
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ use Livewire\Component;
|
||||
|
||||
class Index extends Component
|
||||
{
|
||||
public mixed $posts;
|
||||
public array $posts;
|
||||
|
||||
public function render(): View|ViewFactory
|
||||
{
|
||||
|
||||
@@ -56,10 +56,10 @@ class ProfileEditDetailzForm extends Form
|
||||
public int $blood_pressure_down;
|
||||
|
||||
#[Rule('required|boolean')]
|
||||
public int $has_hypo;
|
||||
public int|bool $has_hypo;
|
||||
|
||||
#[Rule('required|boolean')]
|
||||
public int $has_hyper;
|
||||
public int|bool $has_hyper;
|
||||
|
||||
#[Rule('nullable')]
|
||||
public string $about_alergy = 'nullable';
|
||||
|
||||
@@ -23,7 +23,7 @@ class MealForm extends Component
|
||||
|
||||
public array $portions;
|
||||
|
||||
public int $quantity;
|
||||
public string $quantity;
|
||||
|
||||
public array $pcs;
|
||||
|
||||
@@ -43,11 +43,6 @@ class MealForm extends Component
|
||||
'portion' => 'required|min:1',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $listeners = ['food-intake-updated' => '$refresh'];
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->diary = Diary::find($this->diaryId);
|
||||
@@ -191,6 +186,11 @@ class MealForm extends Component
|
||||
$this->portions = array_values($filtered);
|
||||
}
|
||||
|
||||
protected function getListeners(): array
|
||||
{
|
||||
return ['food-intake-updated' => '$refresh'];
|
||||
}
|
||||
|
||||
private function addPortionIfItFilled(): void
|
||||
{
|
||||
if (mb_strlen($this->product_name) && $this->quantity && mb_strlen($this->portion)) {
|
||||
|
||||
@@ -4,22 +4,23 @@ namespace App\Livewire\ProductNutritional;
|
||||
|
||||
use App\Models\ProductGroup;
|
||||
use App\Models\ProductNutritionalValue;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
class Create extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public string $name;
|
||||
public string $name = '';
|
||||
|
||||
public int $product_group;
|
||||
public int|string $product_group;
|
||||
|
||||
public string|null $image;
|
||||
public ?UploadedFile $image = null;
|
||||
|
||||
public string $description;
|
||||
public string $description = '';
|
||||
|
||||
public string $formulations;
|
||||
|
||||
@@ -27,11 +28,11 @@ class Create extends Component
|
||||
|
||||
public float $proteins_on_100gr;
|
||||
|
||||
public float $fats_on_100gr;
|
||||
public float $fats_on_100gr;
|
||||
|
||||
public float $carbohydrates_on_100gr;
|
||||
|
||||
public int $portion_mass_gr;
|
||||
public int $portion_mass_gr = 0;
|
||||
|
||||
public float $energy_on_portion;
|
||||
|
||||
@@ -53,19 +54,18 @@ class Create extends Component
|
||||
$productNutritionalVal = ProductNutritionalValue::create([
|
||||
'name' => $this->name,
|
||||
'product_group_id' => $this->product_group,
|
||||
/** @phpstan-ignore-next-line */
|
||||
'image' => is_null($this->image) ? '' : $this->image->store('product_nutritional', 'public'),
|
||||
'image' => is_null($this->image) ? '' : $this->image->store('product_nutritional'),
|
||||
'description' => $this->description ?? '',
|
||||
'formulations' => $this->formulations ?? '',
|
||||
'energy_on_100gr' => (int) $this->energy_on_100gr,
|
||||
'proteins_on_100gr' => (float) $this->proteins_on_100gr,
|
||||
'fats_on_100gr' => (float) $this->fats_on_100gr,
|
||||
'carbohydrates_on_100gr' => (float) $this->carbohydrates_on_100gr,
|
||||
'portion_mass_gr' => (int) $this->portion_mass_gr,
|
||||
'energy_on_portion' => (float) $this->energy_on_portion,
|
||||
'proteins_on_portion' => (float) $this->proteins_on_portion,
|
||||
'fats_on_portion' => (float) $this->fats_on_portion,
|
||||
'carbohydrates_on_portion' => (float) $this->carbohydrates_on_portion,
|
||||
'energy_on_100gr' => $this->energy_on_100gr,
|
||||
'proteins_on_100gr' => $this->proteins_on_100gr,
|
||||
'fats_on_100gr' => $this->fats_on_100gr,
|
||||
'carbohydrates_on_100gr' => $this->carbohydrates_on_100gr,
|
||||
'portion_mass_gr' => $this->portion_mass_gr,
|
||||
'energy_on_portion' => $this->energy_on_portion,
|
||||
'proteins_on_portion' => $this->proteins_on_portion,
|
||||
'fats_on_portion' => $this->fats_on_portion,
|
||||
'carbohydrates_on_portion' => $this->carbohydrates_on_portion,
|
||||
]);
|
||||
|
||||
$this->curProductNutritionalValue = $productNutritionalVal;
|
||||
@@ -109,17 +109,17 @@ class Create extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function updated(string $name, string|int|null $value): void
|
||||
public function updated(string $name, string $value): void
|
||||
{
|
||||
if ($name === 'portion_mass_gr') {
|
||||
$this->recalulatePortionVals((int) $this->portion_mass_gr);
|
||||
$this->recalulatePortionVals($this->portion_mass_gr);
|
||||
}
|
||||
|
||||
if (
|
||||
(int) $this->portion_mass_gr > 0
|
||||
&& in_array($name, ['energy_on_portion', 'proteins_on_portion', 'fats_on_portion', 'carbohydrates_on_portion'])
|
||||
$this->portion_mass_gr > 0 &&
|
||||
in_array($name, ['energy_on_portion', 'proteins_on_portion', 'fats_on_portion', 'carbohydrates_on_portion'])
|
||||
) {
|
||||
$this->recalulateVals((int) $this->portion_mass_gr);
|
||||
$this->recalulateVals($this->portion_mass_gr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,22 +4,23 @@ namespace App\Livewire\ProductNutritional;
|
||||
|
||||
use App\Models\ProductGroup;
|
||||
use App\Models\ProductNutritionalValue;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
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 string $name;
|
||||
public string $name = '';
|
||||
|
||||
public int $product_group;
|
||||
public int|string $product_group;
|
||||
|
||||
public string|null $image;
|
||||
public UploadedFile|string $image = '';
|
||||
|
||||
public string $description;
|
||||
public string $description = '';
|
||||
|
||||
public string $formulations;
|
||||
|
||||
@@ -31,7 +32,7 @@ class Edit extends Component
|
||||
|
||||
public float $carbohydrates_on_100gr;
|
||||
|
||||
public int $portion_mass_gr;
|
||||
public int $portion_mass_gr = 0;
|
||||
|
||||
public float $energy_on_portion;
|
||||
|
||||
@@ -70,8 +71,7 @@ class Edit extends Component
|
||||
public function save(): void
|
||||
{
|
||||
if (! is_string($this->image)) {
|
||||
/** @phpstan-ignore-next-line */
|
||||
$this->product->image = $this->image->store('product_nutritional', 'public');
|
||||
$this->product->image = $this->image->store('product_nutritional');
|
||||
}
|
||||
|
||||
$this->product->fill([
|
||||
@@ -79,15 +79,15 @@ class Edit extends Component
|
||||
'product_group_id' => $this->product_group,
|
||||
'description' => $this->description ?? '',
|
||||
'formulations' => $this->formulations ?? '',
|
||||
'energy_on_100gr' => (int) $this->energy_on_100gr,
|
||||
'proteins_on_100gr' => (float) $this->proteins_on_100gr,
|
||||
'fats_on_100gr' => (float) $this->fats_on_100gr,
|
||||
'carbohydrates_on_100gr' => (float) $this->carbohydrates_on_100gr,
|
||||
'portion_mass_gr' => (int) $this->portion_mass_gr,
|
||||
'energy_on_100gr' => $this->energy_on_100gr,
|
||||
'proteins_on_100gr' => $this->proteins_on_100gr,
|
||||
'fats_on_100gr' => $this->fats_on_100gr,
|
||||
'carbohydrates_on_100gr' => $this->carbohydrates_on_100gr,
|
||||
'portion_mass_gr' => $this->portion_mass_gr,
|
||||
'energy_on_portion' => (int) $this->energy_on_portion,
|
||||
'proteins_on_portion' => (float) $this->proteins_on_portion,
|
||||
'fats_on_portion' => (float) $this->fats_on_portion,
|
||||
'carbohydrates_on_portion' => (float) $this->carbohydrates_on_portion,
|
||||
'proteins_on_portion' => $this->proteins_on_portion,
|
||||
'fats_on_portion' => $this->fats_on_portion,
|
||||
'carbohydrates_on_portion' => $this->carbohydrates_on_portion,
|
||||
]);
|
||||
|
||||
$this->product->save();
|
||||
@@ -133,17 +133,17 @@ class Edit extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function updated(string $name, string|int|null $value): void
|
||||
public function updated(string $name, string $value): void
|
||||
{
|
||||
if ($name === 'portion_mass_gr') {
|
||||
$this->recalulatePortionVals((int) $this->portion_mass_gr);
|
||||
$this->recalulatePortionVals($this->portion_mass_gr);
|
||||
}
|
||||
|
||||
if (
|
||||
(int) $this->portion_mass_gr > 0
|
||||
$this->portion_mass_gr > 0
|
||||
&& in_array($name, ['energy_on_portion', 'proteins_on_portion', 'fats_on_portion', 'carbohydrates_on_portion'])
|
||||
) {
|
||||
$this->recalulateVals((int) $this->portion_mass_gr);
|
||||
$this->recalulateVals($this->portion_mass_gr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,19 +12,12 @@ class CircumferenceChart extends Component
|
||||
{
|
||||
public User $user;
|
||||
|
||||
/**
|
||||
* event listeners
|
||||
*
|
||||
* @var array
|
||||
* */
|
||||
protected $listeners = ['circumference-chart-updated' => '$refresh'];
|
||||
|
||||
public function render(): View|ViewFactory
|
||||
{
|
||||
$lastOneMisure = $this
|
||||
->user
|
||||
->circumference_measures()
|
||||
->orderBy('updated_at', 'desc')
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
$lastFourMisures = $this
|
||||
@@ -42,7 +35,7 @@ class CircumferenceChart extends Component
|
||||
->setColors(['#b2df8a', '#1f78b4', '#e3a6a6']);
|
||||
|
||||
$lastFourMisures->each(
|
||||
function ($item, $key) use ($lineChartModel) {
|
||||
function ($item) use ($lineChartModel) {
|
||||
$createdAt = \Carbon\Carbon::parse($item['created_at'])->format('d.m.y');
|
||||
$lineChartModel->addSeriesPoint(__('chest'), $createdAt, $item['chest_circumference']);
|
||||
$lineChartModel->addSeriesPoint(__('waist'), $createdAt, $item['waist_circumference']);
|
||||
@@ -59,4 +52,9 @@ class CircumferenceChart extends Component
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected function getListeners(): array
|
||||
{
|
||||
return ['circumference-chart-updated' => '$refresh'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class DescriptionForm extends Component
|
||||
$this->description = $this->user->detailz->additional_info ?? '';
|
||||
}
|
||||
|
||||
public function updatedDescription(mixed $value): void
|
||||
public function updatedDescription(string $value): void
|
||||
{
|
||||
$userDetailz = $this->user->detailz;
|
||||
|
||||
@@ -47,7 +47,7 @@ class DescriptionForm extends Component
|
||||
]
|
||||
);
|
||||
|
||||
if (! $curUserDetailez->id) {
|
||||
if (! isset($curUserDetailez->id)) {
|
||||
$curUserDetailez->save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ namespace App\Livewire\Profile;
|
||||
use App\Livewire\Forms\ProfileEditDetailzForm;
|
||||
use App\Models\User;
|
||||
use App\Models\UserDetailz;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class EditDetailzForm extends Component
|
||||
{
|
||||
@@ -19,9 +19,9 @@ class EditDetailzForm extends Component
|
||||
|
||||
public string $currentPassword;
|
||||
|
||||
public string $newPassword;
|
||||
public string $newPassword = '';
|
||||
|
||||
public string $newPasswordConfirm;
|
||||
public string $newPasswordConfirm = '';
|
||||
|
||||
public array $validatedData = [];
|
||||
|
||||
|
||||
@@ -2,47 +2,30 @@
|
||||
|
||||
namespace App\Livewire\Profile;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
|
||||
use Livewire\Component;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
use Livewire\WithFileUploads;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class PhotoForm extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
/**
|
||||
* The component's state.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $state = [];
|
||||
public array $state = [];
|
||||
|
||||
/**
|
||||
* The new avatar for the user.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $photo;
|
||||
public UploadedFile|string $photo = '';
|
||||
|
||||
public bool $isOnline = false;
|
||||
public bool|int $isOnline = false;
|
||||
|
||||
/**
|
||||
* User model
|
||||
*
|
||||
* @var \App\Models\User
|
||||
*/
|
||||
public $user;
|
||||
public User $user;
|
||||
|
||||
/**
|
||||
* Prepare the component.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function mount()
|
||||
public function mount(): void
|
||||
{
|
||||
$this->state = $this->user->withoutRelations()->toArray();
|
||||
|
||||
@@ -58,12 +41,7 @@ class PhotoForm extends Component
|
||||
$this->isOnline = now()->unix() - $lastActivity < 150;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user's profile information.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateProfileInformation(UpdatesUserProfileInformation $updater)
|
||||
public function updateProfileInformation(UpdatesUserProfileInformation $updater): void
|
||||
{
|
||||
$this->resetErrorBag();
|
||||
|
||||
@@ -77,31 +55,21 @@ class PhotoForm extends Component
|
||||
$this->dispatch('saved');
|
||||
}
|
||||
|
||||
public function updatedPhoto(mixed $newPhoto): void
|
||||
public function updatedPhoto(TemporaryUploadedFile $newPhoto): void
|
||||
{
|
||||
Auth::user()->updateProfilePhoto($newPhoto);
|
||||
|
||||
$this->dispatch('saved');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user's profile photo.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteProfilePhoto()
|
||||
public function deleteProfilePhoto(): void
|
||||
{
|
||||
Auth::user()->deleteProfilePhoto();
|
||||
|
||||
$this->dispatch('refresh-navigation-menu');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current user of the application.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUserProperty()
|
||||
public function getUserProperty(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Livewire\Profile;
|
||||
|
||||
use Livewire\Component;
|
||||
use Masmerise\Toaster\Toaster;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use App\Models\User;
|
||||
use App\Models\UserDetailz;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
use Masmerise\Toaster\Toaster;
|
||||
|
||||
class ShowDetailz extends Component
|
||||
{
|
||||
@@ -19,11 +19,11 @@ class ShowDetailz extends Component
|
||||
|
||||
public UserDetailz $userDetailz;
|
||||
|
||||
public int $publicity;
|
||||
public bool|int $publicity;
|
||||
|
||||
public int $is_bedtime_fillable;
|
||||
public bool|int $is_bedtime_fillable;
|
||||
|
||||
public int $is_mood_fillable;
|
||||
public bool|int $is_mood_fillable;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
|
||||
@@ -12,11 +12,6 @@ class WeightChart extends Component
|
||||
{
|
||||
public User $user;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* */
|
||||
protected $listeners = ['weight-chart-updated' => '$refresh'];
|
||||
|
||||
public function render(): View|ViewFactory
|
||||
{
|
||||
$areaChartModel =
|
||||
@@ -46,4 +41,9 @@ class WeightChart extends Component
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected function getListeners(): array
|
||||
{
|
||||
return ['weight-chart-updated' => '$refresh'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,35 +5,30 @@ namespace App\Livewire\Registration;
|
||||
use App\Actions\Fortify\CreateNewUser;
|
||||
use App\Rules\MinWords;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
// use Laravel\Fortify\Contracts\RegisterResponse;
|
||||
// use Illuminate\Contracts\Auth\StatefulGuard;
|
||||
// use App\Models\User;
|
||||
// use App\Models\UserDetailz;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Livewire\Component;
|
||||
|
||||
// use \Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
use Livewire\Features\SupportRedirects\Redirector;
|
||||
|
||||
class Step1 extends Component
|
||||
{
|
||||
public string $step;
|
||||
|
||||
public string $first_name;
|
||||
public string $first_name = '';
|
||||
|
||||
public string $last_name;
|
||||
public string $last_name = '';
|
||||
|
||||
public string $email;
|
||||
public string $email = '';
|
||||
|
||||
public string $password;
|
||||
public string $password = '';
|
||||
|
||||
public string $password_confirmation;
|
||||
public string $password_confirmation = '';
|
||||
|
||||
public string $birthdate;
|
||||
|
||||
@@ -45,35 +40,35 @@ class Step1 extends Component
|
||||
|
||||
public string $lang = 'ru';
|
||||
|
||||
public int $weight;
|
||||
public string $weight = '';
|
||||
|
||||
public int $height;
|
||||
public string $height = '';
|
||||
|
||||
public int $chest_circumference;
|
||||
public string $chest_circumference = '';
|
||||
|
||||
public int $waist_circumference;
|
||||
public string $waist_circumference = '';
|
||||
|
||||
public int $hip_circumference;
|
||||
public string $hip_circumference = '';
|
||||
|
||||
public int $blood_pressure_up;
|
||||
public string $blood_pressure_up = '';
|
||||
|
||||
public int $blood_pressure_down;
|
||||
public string $blood_pressure_down = '';
|
||||
|
||||
public int $has_hypo = 0;
|
||||
public int|string $has_hypo = 0;
|
||||
|
||||
public int $has_hyper = 0;
|
||||
public int|string $has_hyper = 0;
|
||||
|
||||
public string $about_alergy;
|
||||
public string $about_alergy = '';
|
||||
|
||||
public string $about_taking_pils;
|
||||
public string $about_taking_pils = '';
|
||||
|
||||
public string $about_sport_hobbies;
|
||||
public string $about_sport_hobbies = '';
|
||||
|
||||
public string $favorite_foods;
|
||||
public string $favorite_foods = '';
|
||||
|
||||
public string $unfavorite_foods;
|
||||
public string $unfavorite_foods = '';
|
||||
|
||||
public string $additional_info;
|
||||
public string $additional_info = '';
|
||||
|
||||
public function mount(string $step): void
|
||||
{
|
||||
@@ -88,7 +83,7 @@ class Step1 extends Component
|
||||
->extends('layouts.register');
|
||||
}
|
||||
|
||||
public function nextStep(): RedirectResponse
|
||||
public function nextStep(): RedirectResponse|Redirector
|
||||
{
|
||||
$validatedData = Validator::make(
|
||||
$this->getValidateData($this->step),
|
||||
@@ -109,7 +104,7 @@ class Step1 extends Component
|
||||
);
|
||||
}
|
||||
|
||||
public function skipStep(): RedirectResponse
|
||||
public function skipStep(): RedirectResponse|Redirector
|
||||
{
|
||||
$validatedData = $this->getValidateData($this->step);
|
||||
$registrationdata = session()->get('registrationdata', []);
|
||||
@@ -126,9 +121,9 @@ class Step1 extends Component
|
||||
);
|
||||
}
|
||||
|
||||
public function goBack(): RedirectResponse
|
||||
public function goBack(): RedirectResponse|Redirector
|
||||
{
|
||||
$nextStep = 'step'. (((int) Str::replaceFirst('step', '', $this->step)) - 1);
|
||||
$nextStep = 'step'.((int) Str::replaceFirst('step', '', $this->step) - 1);
|
||||
|
||||
return redirect()
|
||||
->route(
|
||||
@@ -139,7 +134,7 @@ class Step1 extends Component
|
||||
);
|
||||
}
|
||||
|
||||
public function finishRegistretion(): RedirectResponse
|
||||
public function finishRegistretion(): RedirectResponse|Redirector
|
||||
{
|
||||
$validatedData = Validator::make(
|
||||
$this->getValidateData($this->step),
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Livewire;
|
||||
|
||||
// use App\Models\BlogPost;
|
||||
use App\Models\BlogPost;
|
||||
use App\Models\Recipe;
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
@@ -11,16 +13,17 @@ use Livewire\Component;
|
||||
|
||||
class TagsComponent extends Component
|
||||
{
|
||||
public mixed $tags;
|
||||
public string $tags;
|
||||
|
||||
public mixed $parentComponent;
|
||||
public Recipe|BlogPost $parentComponent;
|
||||
|
||||
// protected $listeners = ['tagAdded', 'tagRemoved'];
|
||||
|
||||
public function mount(mixed $parentComponent = null): void
|
||||
public function mount(Recipe|BlogPost|null $parentComponent = null): void
|
||||
{
|
||||
/* $allTags = Tag::all(); */
|
||||
$curTags = $parentComponent ? $parentComponent->tags->unique()->pluck('name') : [];
|
||||
/* $allTags = Tag::all(); */
|
||||
// $curTags = $parentComponent && isset($parentComponent['tags']) ? $parentComponent['tags']->unique()->pluck('name') : [];
|
||||
$this->tags = json_encode($curTags);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ namespace App\Livewire\User;
|
||||
|
||||
use App\Models\CircumferenceMeasure;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use LivewireUI\Modal\ModalComponent;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use LivewireUI\Modal\ModalComponent;
|
||||
|
||||
class AddCircumference extends ModalComponent
|
||||
{
|
||||
|
||||
@@ -4,10 +4,10 @@ namespace App\Livewire\User;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\WeightMeasure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use LivewireUI\Modal\ModalComponent;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use LivewireUI\Modal\ModalComponent;
|
||||
|
||||
class AddWeight extends ModalComponent
|
||||
{
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
* App\Models\BlogPostLike
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
/**
|
||||
* App\Models\Chat
|
||||
@@ -37,7 +37,7 @@ class Chat extends Model
|
||||
|
||||
protected $casts = ['created_at' => 'datetime:Y-m-d H:i:s'];
|
||||
|
||||
public function scopeWithLastUserMessage(mixed $query, int $userId): Builder
|
||||
public function scopeWithLastUserMessage(Builder $query, int $userId): ?Model
|
||||
{
|
||||
return $query
|
||||
->where('from_user_id', $userId)
|
||||
@@ -59,7 +59,7 @@ class Chat extends Model
|
||||
->limit(20);
|
||||
}
|
||||
|
||||
public function scopeWithLastMessage(Builder $query, int $userId, int $recipientId): null|object
|
||||
public function scopeWithLastMessage(Builder $query, int $userId, int $recipientId): ?Model
|
||||
{
|
||||
return $query
|
||||
->where('from_user_id', $userId)
|
||||
|
||||
@@ -6,7 +6,6 @@ use Iben\Statable\Statable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
/**
|
||||
* App\Models\ChosenDiet
|
||||
@@ -18,7 +17,6 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
* @property string $start_date
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
*
|
||||
* @property-read \App\Models\Diet|null $diet
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Iben\Statable\Models\StateHistory> $stateHistory
|
||||
* @property-read int|null $state_history_count
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
/**
|
||||
* App\Models\Diary
|
||||
@@ -19,9 +19,8 @@ use Illuminate\Database\Query\Builder;
|
||||
* @property string $retire
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property int $closed
|
||||
* @property int|bool $closed
|
||||
* @property string $comment
|
||||
*
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ConsultantDiaryComment> $consultant_comments
|
||||
* @property-read int|null $consultant_comments_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Meal> $meals
|
||||
|
||||
@@ -8,13 +8,8 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
use Illuminate\Support\Str;
|
||||
use Spatie\Sluggable\HasSlug;
|
||||
use Spatie\Sluggable\SlugOptions;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* App\Models\Diet
|
||||
@@ -29,7 +24,6 @@ use Spatie\Sluggable\SlugOptions;
|
||||
* @property mixed $daily_schedule A list of planned foods
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
*
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\User> $author
|
||||
* @property-read int|null $author_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ChosenDiet> $choses
|
||||
@@ -70,10 +64,9 @@ class Diet extends Model implements Viewable
|
||||
{
|
||||
use HasFactory, InteractsWithViews;
|
||||
|
||||
protected $withCount = [
|
||||
'likes',
|
||||
'comments',
|
||||
'choses',
|
||||
protected $casts = [
|
||||
'type' => 'array',
|
||||
'daily_schedule' => 'array',
|
||||
];
|
||||
|
||||
private array $allowedDietTypes = [
|
||||
@@ -83,13 +76,17 @@ class Diet extends Model implements Viewable
|
||||
'veg',
|
||||
];
|
||||
|
||||
// protected $casts = [
|
||||
// 'type' => 'array',
|
||||
// 'packet1_options' => 'array',
|
||||
// 'packet2_options' => 'array',
|
||||
// 'packet3_options' => 'array',
|
||||
// protected $withCount = [
|
||||
// 'likes',
|
||||
// 'comments',
|
||||
// 'choses',
|
||||
// ];
|
||||
|
||||
public static function getWithLikesCommentsChosesCount(): Builder
|
||||
{
|
||||
return self::withCount(['likes', 'comments', 'choses']);
|
||||
}
|
||||
|
||||
public function author(): BelongsToMany
|
||||
{
|
||||
return $this
|
||||
@@ -113,7 +110,7 @@ class Diet extends Model implements Viewable
|
||||
return $this->hasMany(DietLike::class);
|
||||
}
|
||||
|
||||
public function isLiked(): bool
|
||||
public function isLiked(): bool|int
|
||||
{
|
||||
if (auth()->user()) {
|
||||
return auth()->user()->diet_likes()->forDiet($this)->count() > 0;
|
||||
@@ -122,7 +119,7 @@ class Diet extends Model implements Viewable
|
||||
return false;
|
||||
}
|
||||
|
||||
public function removeLike(): bool
|
||||
public function removeLike(): bool|int
|
||||
{
|
||||
if (auth()->user()) {
|
||||
return auth()->user()->diet_likes()->forDiet($this)->delete();
|
||||
@@ -133,7 +130,7 @@ class Diet extends Model implements Viewable
|
||||
|
||||
public function types(): Attribute
|
||||
{
|
||||
$data = $this->unserializeOptionsArr($this->type);
|
||||
$data = $this->type;
|
||||
|
||||
return new Attribute(
|
||||
get: fn () => array_keys($data),
|
||||
@@ -142,7 +139,7 @@ class Diet extends Model implements Viewable
|
||||
|
||||
public function schedules(): Attribute
|
||||
{
|
||||
$data = $this->unserializeOptionsArr($this->daily_schedule);
|
||||
$data = $this->daily_schedule;
|
||||
|
||||
return new Attribute(
|
||||
get: fn () => $data,
|
||||
@@ -154,22 +151,22 @@ class Diet extends Model implements Viewable
|
||||
return $this->hasMany(ChosenDiet::class);
|
||||
}
|
||||
|
||||
public function scopeDurationMin(Builder $query, int $days): Builder
|
||||
public function scopeDurationMin(Builder $query, string $days): Builder
|
||||
{
|
||||
return $query->where('duration', '>=', $days);
|
||||
}
|
||||
|
||||
public function scopeDurationMax(Builder $query, int $days): Builder
|
||||
public function scopeDurationMax(Builder $query, string $days): Builder
|
||||
{
|
||||
return $query->where('duration', '<=', $days);
|
||||
}
|
||||
|
||||
public function scopeInvolvedMin(Builder $query, int $number): Builder
|
||||
public function scopeInvolvedMin(Builder $query, string $number): Builder
|
||||
{
|
||||
return $query->having('choses_count', '>=', $number);
|
||||
}
|
||||
|
||||
public function scopeInvolvedMax(Builder $query, int $number): Builder
|
||||
public function scopeInvolvedMax(Builder $query, string $number): Builder
|
||||
{
|
||||
return $query->having('choses_count', '<=', $number);
|
||||
}
|
||||
@@ -189,13 +186,4 @@ class Diet extends Model implements Viewable
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function unserializeOptionsArr(string $str): array
|
||||
{
|
||||
if (preg_match('/^".*"$/', $str)) {
|
||||
return json_decode(stripslashes(mb_substr($str, 1, -1)), true);
|
||||
}
|
||||
|
||||
return json_decode(stripslashes($str), true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class DietComment extends Model
|
||||
return $this->hasMany(DietCommentUpvote::class, 'comment_id');
|
||||
}
|
||||
|
||||
public function isUpVoted(): bool
|
||||
public function isUpVoted(): bool|int
|
||||
{
|
||||
if (auth()->user()) {
|
||||
return auth()
|
||||
@@ -68,7 +68,7 @@ class DietComment extends Model
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isDownVoted(): bool
|
||||
public function isDownVoted(): bool|int
|
||||
{
|
||||
if (auth()->user()) {
|
||||
return auth()
|
||||
@@ -81,7 +81,7 @@ class DietComment extends Model
|
||||
return false;
|
||||
}
|
||||
|
||||
public function removeUpVote(): bool
|
||||
public function removeUpVote(): bool|int
|
||||
{
|
||||
if (auth()->user()) {
|
||||
return auth()
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
* App\Models\DietCommentUpvote
|
||||
@@ -16,7 +16,6 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
* @property string $type
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
*
|
||||
* @property-read \App\Models\User $author
|
||||
* @property-read \App\Models\DietComment|null $diet_comment
|
||||
*
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
/**
|
||||
* App\Models\DietLike
|
||||
|
||||
@@ -34,6 +34,7 @@ use Laravel\Sanctum\HasApiTokens;
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property int $is_consultant
|
||||
* @property string $consultant_state
|
||||
* @property int $is_public_profile 0 only friends, 1 all
|
||||
*
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\UserAttachment> $attachments
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
/**
|
||||
* App\Models\UserAttachment
|
||||
@@ -20,7 +20,6 @@ use Illuminate\Database\Query\Builder;
|
||||
* @property mixed $specs
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
*
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Meal> $meals
|
||||
* @property-read int|null $meals_count
|
||||
* @property-read \App\Models\User $user
|
||||
|
||||
@@ -12,7 +12,7 @@ class ConsultantRequestStarted extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
private ConsultantEducation $education;
|
||||
public ConsultantEducation $education;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\ChosenDiet;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
@@ -12,37 +11,23 @@ class DietStarted extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public ChosenDiet $chosenDiet;
|
||||
public object $chosenDiet;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ChosenDiet $chosenDiet)
|
||||
public function __construct(object $chosenDiet)
|
||||
{
|
||||
$this->afterCommit();
|
||||
$this->chosenDiet = $chosenDiet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
return (new MailMessage())
|
||||
->line('you are successful started diet named: '.($this->chosenDiet->diet->name ?? 'NoName'))
|
||||
@@ -50,13 +35,7 @@ class DietStarted extends Notification implements ShouldQueue
|
||||
->line('Thank you for using our application!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class MinWords implements Rule
|
||||
$this->minWords = $minWords;
|
||||
}
|
||||
|
||||
public function passes($attribute, $value)
|
||||
public function passes(mixed $attribute, mixed $value): bool|int
|
||||
{
|
||||
$wordCount = count(preg_split('/\W+/u', $value, -1, PREG_SPLIT_NO_EMPTY));
|
||||
|
||||
|
||||
@@ -17,55 +17,63 @@ class FeedService
|
||||
$dateMin = Carbon::parse($dateMax)->subDays(10);
|
||||
|
||||
$sql = <<<'EOF'
|
||||
SELECT
|
||||
p.id,
|
||||
p.title,
|
||||
(
|
||||
(p.likes_count + p.comments_count) /
|
||||
((UNIX_TIMESTAMP(GREATEST(p.created_at,
|
||||
COALESCE((SELECT MAX(l.created_at) FROM blog_post_likes l WHERE l.blog_post_id = p.id), p.created_at),
|
||||
COALESCE((SELECT MAX(c.created_at) FROM blog_post_comments c WHERE c.blog_post_id = p.id), p.created_at)
|
||||
)) - UNIX_TIMESTAMP(p.created_at))/60 + 1
|
||||
) ^ 1.8
|
||||
) AS popularity
|
||||
FROM
|
||||
(SELECT
|
||||
`blog_posts`.id,
|
||||
blog_posts.title,
|
||||
blog_posts.created_at,
|
||||
COUNT(blog_post_comments.id) AS comments_count,
|
||||
COUNT(blog_post_likes.id) AS likes_count
|
||||
FROM
|
||||
`blog_posts`
|
||||
LEFT JOIN blog_post_comments ON blog_post_comments.blog_post_id = blog_posts.id
|
||||
LEFT JOIN blog_post_likes ON blog_post_likes.blog_post_id = blog_posts.id
|
||||
GROUP BY blog_posts.id) p
|
||||
ORDER BY popularity DESC;
|
||||
EOF;
|
||||
SELECT
|
||||
p.id,
|
||||
p.title,
|
||||
(
|
||||
(p.likes_count + p.comments_count) /
|
||||
((UNIX_TIMESTAMP(GREATEST(p.created_at,
|
||||
COALESCE((SELECT MAX(l.created_at) FROM blog_post_likes l WHERE l.blog_post_id = p.id), p.created_at),
|
||||
COALESCE((SELECT MAX(c.created_at) FROM blog_post_comments c WHERE c.blog_post_id = p.id), p.created_at)
|
||||
)) - UNIX_TIMESTAMP(p.created_at))/60 + 1
|
||||
) ^ 1.8
|
||||
) AS popularity
|
||||
FROM
|
||||
(SELECT
|
||||
`blog_posts`.id,
|
||||
blog_posts.title,
|
||||
blog_posts.created_at,
|
||||
COUNT(blog_post_comments.id) AS comments_count,
|
||||
COUNT(blog_post_likes.id) AS likes_count
|
||||
FROM
|
||||
`blog_posts`
|
||||
LEFT JOIN blog_post_comments ON blog_post_comments.blog_post_id = blog_posts.id
|
||||
LEFT JOIN blog_post_likes ON blog_post_likes.blog_post_id = blog_posts.id
|
||||
GROUP BY blog_posts.id) p
|
||||
ORDER BY popularity DESC;
|
||||
EOF;
|
||||
|
||||
$hotBlogPosts = collect(
|
||||
DB::select(DB::raw($sql))
|
||||
)->map(fn ($post) => BlogPost::find($post->id))
|
||||
->take(16)->chunk(4);
|
||||
DB::select($sql)
|
||||
)
|
||||
->map(fn ($post) => BlogPost::find($post->id))
|
||||
->take(16)
|
||||
->chunk(4);
|
||||
|
||||
$newbiesBlogPosts = User::orderBy('created_at', 'desc')
|
||||
->withCount('author_of_blog_post')
|
||||
->get()
|
||||
->filter(fn ($u) => $u->author_of_blog_post_count > 0)->take(4)
|
||||
->filter(fn ($u) => $u->author_of_blog_post_count > 0)
|
||||
->take(4)
|
||||
->pluck('id')
|
||||
->map(fn ($id) => User::find($id)->author_of_blog_post()->limit(2)->get())
|
||||
->flatten()
|
||||
->random();
|
||||
|
||||
$randomRecipe = Recipe::where('created_at', '>=', $dateMin)
|
||||
Recipe::where('created_at', '>=', $dateMin)
|
||||
->where('created_at', '<=', $dateMax)
|
||||
->inRandomOrder()
|
||||
->limit(2)
|
||||
->get();
|
||||
|
||||
$firstCollection = $hotBlogPosts->first()->push($newbiesBlogPosts->first())->push($randomRecipe->first());
|
||||
$secondCollection = $hotBlogPosts->skip(1)->first()->push($newbiesBlogPosts->skip(1)->first())->push($randomRecipe->skip(1)->first());
|
||||
$firstCollection = collect([$hotBlogPosts->first(), $newbiesBlogPosts->first()]);
|
||||
$secondCollection = collect([$hotBlogPosts->skip(1)->first(), $newbiesBlogPosts->skip(1)->first()]);
|
||||
|
||||
return $firstCollection->concat($secondCollection)->filter(fn ($el) => ! is_null($el) && $el->id);
|
||||
|
||||
// $firstCollection = $hotBlogPosts->first()->push($newbiesBlogPosts->first())->push($randomRecipe->first());
|
||||
// $secondCollection = $hotBlogPosts->skip(1)->first()->push($newbiesBlogPosts->skip(1)->first())->push($randomRecipe->skip(1)->first());
|
||||
|
||||
// return $firstCollection->concat($secondCollection)->filter(fn ($el) => ! is_null($el) && $el->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ return [
|
||||
| using this Eloquent Model. You can override this if you really need to.
|
||||
|
|
||||
*/
|
||||
'model' => \Tonysm\RichTextLaravel\Models\RichText::class,
|
||||
// 'model' => \Tonysm\RichTextLaravel\Models\RichText::class,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
return [
|
||||
'article' => [
|
||||
// class of your domain object
|
||||
'class' => App\Article::class,
|
||||
// 'class' => App\Article::class,
|
||||
|
||||
// name of the graph (default is "default")
|
||||
'graph' => 'article',
|
||||
|
||||
@@ -4,10 +4,8 @@ namespace Database\Factories;
|
||||
|
||||
use App\Models\BlogPost;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Models\User;
|
||||
use Faker\Provider\Youtube;
|
||||
use Faker\Generator;
|
||||
|
||||
|
||||
@@ -2,20 +2,18 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use FakerRestaurant\Provider\en_US\Restaurant;
|
||||
use App\Models\Diet;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Http\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Faker\Generator;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Diet>
|
||||
* @property Generator|Restaurant $faker
|
||||
*/
|
||||
class DietFactory extends Factory
|
||||
{
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
@@ -26,13 +24,13 @@ class DietFactory extends Factory
|
||||
$faker = \Faker\Factory::create();
|
||||
$this->faker->addProvider(new Restaurant($faker));
|
||||
$dietDuration = $this->faker->randomElement([7, 14, 21]);
|
||||
$dietState = $this->faker->randomElement(['active','draft','archived']);
|
||||
$dietState = $this->faker->randomElement(['active', 'draft', 'archived']);
|
||||
$numberOfDefinedDietTypes = $this->faker->numberBetween(1, 4);
|
||||
$expectedDietTypes = ['meat', 'veg', 'corb', 'alko'];
|
||||
$expectedDietTypes = ['meat', 'veg', 'corb', 'alko'];
|
||||
$selectedDietTypes = $this->faker->randomElements($expectedDietTypes, $numberOfDefinedDietTypes);
|
||||
$dietTypes = array_reduce(
|
||||
$selectedDietTypes,
|
||||
function($acc, $el) {
|
||||
function ($acc, $el) {
|
||||
$acc[$el] = true;
|
||||
return $acc;
|
||||
},
|
||||
@@ -47,12 +45,11 @@ class DietFactory extends Factory
|
||||
$file = new File($imageFilePath);
|
||||
$fileLocalPath = Storage::putFile('diets', $file, 'public');
|
||||
|
||||
for($day = 1; $day <= $dietDuration ; $day++) {
|
||||
foreach($dietEatingTypes as $eatingType) {
|
||||
|
||||
for ($day = 1; $day <= $dietDuration; $day++) {
|
||||
foreach ($dietEatingTypes as $eatingType) {
|
||||
$numberOfProductsInCurrentMeel = $this->faker->numberBetween(1, 4);
|
||||
|
||||
for(;$numberOfProductsInCurrentMeel > 0; $numberOfProductsInCurrentMeel--) {
|
||||
for (; $numberOfProductsInCurrentMeel > 0; $numberOfProductsInCurrentMeel--) {
|
||||
$meelName = $this->faker->foodName();
|
||||
$dailySchedule[$day][$eatingType][] = [
|
||||
'name' => $meelName,
|
||||
@@ -77,7 +74,7 @@ class DietFactory extends Factory
|
||||
$dietNamePrefix = $this->faker->randomElement(['Super', 'Keto', 'Fast', 'Detox', 'Power Of', 'Green', 'Healthy', 'Turbo']);
|
||||
|
||||
return [
|
||||
'name' => $dietNamePrefix . " " . $dietName . " Diet",
|
||||
'name' => $dietNamePrefix . ' ' . $dietName . ' Diet',
|
||||
'duration' => $dietDuration,
|
||||
'state' => $dietState,
|
||||
'image' => $fileLocalPath,
|
||||
|
||||
28
database/factories/ProductGroupFactory.php
Normal file
28
database/factories/ProductGroupFactory.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use FakerRestaurant\Provider\en_US\Restaurant;
|
||||
use Faker\Generator;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ProductGroup>
|
||||
* @property Generator|Restaurant $faker
|
||||
*/
|
||||
class ProductGroupFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$this->faker->addProvider(new Restaurant($faker));
|
||||
|
||||
return [
|
||||
'name' => 'Product Group' . $this->faker->foodName(),
|
||||
'description' => $this->faker->realText($this->faker->numberBetween(100, 200)),
|
||||
];
|
||||
}
|
||||
}
|
||||
57
database/factories/ProductNutritionalValueFactory.php
Normal file
57
database/factories/ProductNutritionalValueFactory.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use FakerRestaurant\Provider\en_US\Restaurant;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Http\File;
|
||||
use Faker\Generator;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ProductNutritionalValue>
|
||||
* @property Generator|Restaurant $faker
|
||||
*/ class ProductNutritionalValueFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$this->faker->addProvider(new Restaurant($faker));
|
||||
|
||||
$active = $this->faker->boolean();
|
||||
|
||||
return [
|
||||
'name' => $this->faker->regexify('[A-Za-z0-9]{20}'),
|
||||
'image' => $this->generateImageFile(),
|
||||
'description' => $this->faker->text(),
|
||||
'formulations' => $this->faker->text(),
|
||||
'energy_on_100gr' => $this->faker->numberBetween(0,100),
|
||||
'proteins_on_100gr' => $this->faker->randomFloat(1, 20, 50),
|
||||
'fats_on_100gr' => $this->faker->randomFloat(1, 20, 50),
|
||||
'carbohydrates_on_100gr' => $this->faker->randomFloat(1, 20, 50),
|
||||
'portion_mass_gr' => $this->faker->numberBetween(0, 100),
|
||||
'energy_on_portion' => $this->faker->randomFloat(1,20,50),
|
||||
'proteins_on_portion' => $this->faker->randomFloat(1,20,50),
|
||||
'fats_on_portion' => $this->faker->randomFloat(1,20,50),
|
||||
'carbohydrates_on_portion' => $this->faker->randomFloat(1,20,50),
|
||||
];
|
||||
}
|
||||
|
||||
private function generateImageFile(string $name = 'plans'): string
|
||||
{
|
||||
$images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg'];
|
||||
Storage::fake($name);
|
||||
$imageFileKey = $this->faker->numberBetween(0, 9);
|
||||
$imageFilePath = 'database/assets/images/plans/' . $images[$imageFileKey];
|
||||
$file = new File($imageFilePath);
|
||||
$fileLocalPath = Storage::putFile($name, $file, 'public');
|
||||
|
||||
return $fileLocalPath;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use FakerRestaurant\Provider\en_US\Restaurant;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Faker\Generator;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Tag>
|
||||
* @property Generator|Restaurant $faker
|
||||
*/
|
||||
class TagFactory extends Factory
|
||||
{
|
||||
@@ -21,6 +21,7 @@ class TagFactory extends Factory
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$this->faker->addProvider(new Restaurant($faker));
|
||||
|
||||
return [
|
||||
'name' => $this->faker->foodName(),
|
||||
];
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Jetstream\Features;
|
||||
use Laravel\Jetstream\Team;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
|
||||
@@ -6,12 +6,7 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('product_nutritional_values', function (Blueprint $table) {
|
||||
$table->id();
|
||||
@@ -33,12 +28,7 @@ return new class extends Migration
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('product_nutritional_values');
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ class DatabaseSeeder extends Seeder
|
||||
$this->call(RecipeAuthor::class);
|
||||
$this->call(RecipeCommentSeeder::class);
|
||||
$this->call(RecipeTagSeeder::class);
|
||||
$this->call(DietsSeeder::class);
|
||||
$this->call(BlogPostSeeder::class);
|
||||
$this->call(ProductNutritionalSeeder::class);
|
||||
}
|
||||
}
|
||||
|
||||
24
database/seeders/ProductNutritionalSeeder.php
Normal file
24
database/seeders/ProductNutritionalSeeder.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\ProductGroup;
|
||||
use App\Models\ProductNutritionalValue;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ProductNutritionalSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$products = ProductNutritionalValue::factory()->count(5)->make();
|
||||
|
||||
$products->each(
|
||||
function ($product) {
|
||||
$product->product_group()->associate(ProductGroup::factory()->create());
|
||||
return $product->saveOrFail();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ class ApiTokenPermissionsTest extends TestCase
|
||||
if (! Features::hasApiFeatures()) {
|
||||
$this->markTestSkipped('API support is not enabled.');
|
||||
|
||||
return;
|
||||
// return;
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
|
||||
|
||||
@@ -17,8 +17,6 @@ class CreateApiTokenTest extends TestCase
|
||||
{
|
||||
if (! Features::hasApiFeatures()) {
|
||||
$this->markTestSkipped('API support is not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
|
||||
|
||||
@@ -17,8 +17,6 @@ class DeleteAccountTest extends TestCase
|
||||
{
|
||||
if (! Features::hasAccountDeletionFeatures()) {
|
||||
$this->markTestSkipped('Account deletion is not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
@@ -34,8 +32,6 @@ class DeleteAccountTest extends TestCase
|
||||
{
|
||||
if (! Features::hasAccountDeletionFeatures()) {
|
||||
$this->markTestSkipped('Account deletion is not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
@@ -5,8 +5,9 @@ namespace Tests\Feature;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Jetstream\Features;
|
||||
use Laravel\Jetstream\Http\Livewire\ApiTokenManager;
|
||||
use Laravel\Jetstream\Features;
|
||||
use Laravel\Sanctum\PersonalAccessToken;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -16,14 +17,13 @@ class DeleteApiTokenTest extends TestCase
|
||||
|
||||
public function test_api_tokens_can_be_deleted(): void
|
||||
{
|
||||
if (! Features::hasApiFeatures()) {
|
||||
if (!Features::hasApiFeatures()) {
|
||||
$this->markTestSkipped('API support is not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
|
||||
|
||||
/** @var PersonalAccessToken $token */
|
||||
$token = $user->tokens()->create([
|
||||
'name' => 'Test Token',
|
||||
'token' => Str::random(40),
|
||||
|
||||
185
tests/Feature/Diet/CreateTest.php
Normal file
185
tests/Feature/Diet/CreateTest.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Diet;
|
||||
|
||||
use App\Livewire\Diet\Create;
|
||||
use App\Models\Diet;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\Testing\File;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private File $image;
|
||||
|
||||
private Diet $diet;
|
||||
|
||||
protected User $user;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
Storage::fake('tmp-for-tests');
|
||||
$this->image = UploadedFile::fake()->image('diet.png');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
$this->diet = Diet::factory()->make();
|
||||
}
|
||||
|
||||
public function test_show_form_create_diet(): void
|
||||
{
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->get(route('diet.create'));
|
||||
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_publish_new_diet_success(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$dietCountAtStart = Diet::count();
|
||||
|
||||
$testCase = Livewire::test(Create::class)
|
||||
->set('name', $this->diet->name)
|
||||
->assertSet('name', $this->diet->name)
|
||||
->set('image', $this->image)
|
||||
->set('duration', $this->diet->duration)
|
||||
->assertSet('duration', $this->diet->duration)
|
||||
->set('state', $this->diet->state)
|
||||
->assertSet('state', $this->diet->state)
|
||||
->set('type', $this->diet->type)
|
||||
->assertSet('type', $this->diet->type)
|
||||
->set('details', $this->diet->details)
|
||||
->assertSet('details', $this->diet->details)
|
||||
->set('daily_schedule', $this->diet->daily_schedule)
|
||||
->assertSet('daily_schedule', $this->diet->daily_schedule)
|
||||
->call('publish')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['name', 'image', 'duration', 'state', 'details', 'daily_schedule', 'type']);
|
||||
|
||||
$lastCreatedDiet = Diet::orderBy('id', 'desc')->first();
|
||||
|
||||
$this->assertEquals($dietCountAtStart + 1, Diet::count());
|
||||
|
||||
// $newDietUrl = route('diet.show', $lastCreatedDiet);
|
||||
|
||||
// $testCase->assertRedirect($newDietUrl);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($lastCreatedDiet->image);
|
||||
|
||||
$response = $this->actingAs($this->user)->get(route('diet.index'));
|
||||
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_to_draft_new_diet_success(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$dietCountAtStart = Diet::count();
|
||||
|
||||
$testCase = Livewire::test(Create::class)
|
||||
->set('name', $this->diet->name)
|
||||
->assertSet('name', $this->diet->name)
|
||||
->set('image', $this->image)
|
||||
->set('duration', $this->diet->duration)
|
||||
->assertSet('duration', $this->diet->duration)
|
||||
->set('state', $this->diet->state)
|
||||
->assertSet('state', $this->diet->state)
|
||||
->set('type', $this->diet->type)
|
||||
->assertSet('type', $this->diet->type)
|
||||
->set('details', $this->diet->details)
|
||||
->assertSet('details', $this->diet->details)
|
||||
->set('daily_schedule', $this->diet->daily_schedule)
|
||||
->assertSet('daily_schedule', $this->diet->daily_schedule)
|
||||
->call('addToDrafts')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['name', 'image', 'duration', 'details', 'daily_schedule']);
|
||||
|
||||
self::assertEquals('draft', $testCase->state);
|
||||
|
||||
$lastCreatedDiet = Diet::orderBy('id', 'desc')->first();
|
||||
|
||||
// $newDietUrl = route('diet.show', $lastCreatedDiet);
|
||||
|
||||
// $testCase->assertRedirect($newDietUrl);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($lastCreatedDiet->image);
|
||||
|
||||
$this->assertEquals($dietCountAtStart + 1, Diet::count());
|
||||
|
||||
$response = $this->actingAs($this->user)->get(route('diet.index'));
|
||||
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_to_preview_new_diet_success(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$dietCountAtStart = Diet::count();
|
||||
|
||||
$testCase = Livewire::test(Create::class)
|
||||
->set('name', $this->diet->name)
|
||||
->assertSet('name', $this->diet->name)
|
||||
->set('image', $this->image)
|
||||
->set('duration', $this->diet->duration)
|
||||
->assertSet('duration', $this->diet->duration)
|
||||
->set('state', $this->diet->state)
|
||||
->assertSet('state', $this->diet->state)
|
||||
->set('type', $this->diet->type)
|
||||
->assertSet('type', $this->diet->type)
|
||||
->set('details', $this->diet->details)
|
||||
->assertSet('details', $this->diet->details)
|
||||
->set('daily_schedule', $this->diet->daily_schedule)
|
||||
->assertSet('daily_schedule', $this->diet->daily_schedule)
|
||||
->call('showPreview')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['name', 'image', 'duration', 'details', 'daily_schedule']);
|
||||
|
||||
self::assertEquals('draft', $testCase->state);
|
||||
|
||||
$lastCreatedDiet = Diet::orderBy('id', 'desc')->first();
|
||||
|
||||
// $newDietUrl = route('diet.show', $lastCreatedDiet);
|
||||
|
||||
// $testCase->assertRedirect($newDietUrl);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($lastCreatedDiet->image);
|
||||
|
||||
$this->assertEquals($dietCountAtStart + 1, Diet::count());
|
||||
|
||||
$response = $this->actingAs($this->user)->get(route('diet.index'));
|
||||
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_set_empty_data(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$dietCountAtStart = Diet::count();
|
||||
|
||||
Livewire::test(Create::class)
|
||||
->set('name', null)
|
||||
->set('image', null)
|
||||
->set('duration', null)
|
||||
->set('state', null)
|
||||
->set('type', null)
|
||||
->set('details', null)
|
||||
->set('daily_schedule', null)
|
||||
->call('publish')
|
||||
->assertHasErrors(['name', 'image', 'details', 'type']);
|
||||
|
||||
$this->assertEquals($dietCountAtStart, Diet::count());
|
||||
}
|
||||
}
|
||||
204
tests/Feature/Diet/EditTest.php
Normal file
204
tests/Feature/Diet/EditTest.php
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Diet;
|
||||
|
||||
use App\Models\Diet;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
use App\Livewire\Diet\Edit;
|
||||
use Livewire\Livewire;
|
||||
|
||||
class EditTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private UploadedFile $image;
|
||||
|
||||
private Diet $diet;
|
||||
|
||||
protected User $user;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
Storage::fake('tmp-for-tests');
|
||||
$this->image = UploadedFile::fake()->image('diet.png');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
$this->diet = Diet::factory()->create();
|
||||
}
|
||||
|
||||
public function test_show_form_edit_diet(): void
|
||||
{
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->get(route('diet.edit', $this->diet));
|
||||
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_publish_new_diet_success(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$updatedDietBeforeToAddDatabase = Diet::factory()->make();
|
||||
|
||||
$testCase = Livewire::test(Edit::class, [
|
||||
'diet' => $this->diet,
|
||||
])
|
||||
->set('name', $updatedDietBeforeToAddDatabase->name)
|
||||
->assertSet('name', $updatedDietBeforeToAddDatabase->name)
|
||||
->set('image', $this->image)
|
||||
->set('duration', $updatedDietBeforeToAddDatabase->duration)
|
||||
->assertSet('duration', $updatedDietBeforeToAddDatabase->duration)
|
||||
->set('state', $updatedDietBeforeToAddDatabase->state)
|
||||
->assertSet('state', $updatedDietBeforeToAddDatabase->state)
|
||||
->set('type', $updatedDietBeforeToAddDatabase->type)
|
||||
->assertSet('type', $updatedDietBeforeToAddDatabase->type)
|
||||
->set('details', $updatedDietBeforeToAddDatabase->details)
|
||||
->assertSet('details', $updatedDietBeforeToAddDatabase->details)
|
||||
->set('daily_schedule', $this->diet->daily_schedule)
|
||||
->assertSet('daily_schedule', $this->diet->daily_schedule)
|
||||
->call('publish')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['name', 'image', 'duration', 'state', 'details', 'daily_schedule', 'type']);
|
||||
|
||||
$updatedDietAfterToAddDatabase = Diet::orderByDesc('id')->first();
|
||||
|
||||
$newDietUrl = route('diet.show', $updatedDietAfterToAddDatabase);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($updatedDietAfterToAddDatabase->image);
|
||||
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($updatedDietBeforeToAddDatabase->name, $updatedDietAfterToAddDatabase->name);
|
||||
self::assertEquals($updatedDietBeforeToAddDatabase->duration, $updatedDietAfterToAddDatabase->duration);
|
||||
self::assertEquals($updatedDietBeforeToAddDatabase->state, $updatedDietAfterToAddDatabase->state);
|
||||
self::assertEquals($updatedDietBeforeToAddDatabase->type, $updatedDietAfterToAddDatabase->type);
|
||||
self::assertEquals($updatedDietBeforeToAddDatabase->details, $updatedDietAfterToAddDatabase->details);
|
||||
// self::assertEquals($updatedDietBeforeToAddDatabase->daily_schedule, $updatedDietAfterToAddDatabase->daily_schedule);
|
||||
|
||||
$testCase->assertRedirect($newDietUrl);
|
||||
|
||||
}
|
||||
|
||||
public function test_to_draft_new_diet_success(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$updatedDietBeforeToAddDatabase = Diet::factory()->make();
|
||||
|
||||
$testCase = Livewire::test(Edit::class, [
|
||||
'diet' => $this->diet,
|
||||
])
|
||||
->set('name', $updatedDietBeforeToAddDatabase->name)
|
||||
->assertSet('name', $updatedDietBeforeToAddDatabase->name)
|
||||
->set('image', $this->image)
|
||||
->set('duration', $updatedDietBeforeToAddDatabase->duration)
|
||||
->assertSet('duration', $updatedDietBeforeToAddDatabase->duration)
|
||||
->set('state', $updatedDietBeforeToAddDatabase->state)
|
||||
->assertSet('state', $updatedDietBeforeToAddDatabase->state)
|
||||
->set('type', $updatedDietBeforeToAddDatabase->type)
|
||||
->assertSet('type', $updatedDietBeforeToAddDatabase->type)
|
||||
->set('details', $updatedDietBeforeToAddDatabase->details)
|
||||
->assertSet('details', $updatedDietBeforeToAddDatabase->details)
|
||||
->set('daily_schedule', $this->diet->daily_schedule)
|
||||
->assertSet('daily_schedule', $this->diet->daily_schedule)
|
||||
->call('addToDrafts')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['name', 'image', 'duration', 'state', 'details', 'days', 'type']);
|
||||
|
||||
$updatedDietAfterToAddDatabase = Diet::orderByDesc('id')->first();
|
||||
|
||||
$newDietUrl = route('diet.show', $updatedDietAfterToAddDatabase);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($updatedDietAfterToAddDatabase->image);
|
||||
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($updatedDietBeforeToAddDatabase->name, $updatedDietAfterToAddDatabase->name);
|
||||
self::assertEquals($updatedDietBeforeToAddDatabase->duration, $updatedDietAfterToAddDatabase->duration);
|
||||
self::assertEquals('draft', $updatedDietAfterToAddDatabase->state);
|
||||
self::assertEquals($updatedDietBeforeToAddDatabase->type, $updatedDietAfterToAddDatabase->type);
|
||||
self::assertEquals($updatedDietBeforeToAddDatabase->details, $updatedDietAfterToAddDatabase->details);
|
||||
// self::assertEquals($updatedDietBeforeToAddDatabase->daily_schedule, $updatedDietAfterToAddDatabase->daily_schedule);
|
||||
|
||||
$testCase->assertRedirect($newDietUrl);
|
||||
}
|
||||
|
||||
public function test_to_preview_new_diet_success(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$updatedDietBeforeToAddDatabase = Diet::factory()->make();
|
||||
|
||||
$testCase = Livewire::test(Edit::class, [
|
||||
'diet' => $this->diet,
|
||||
])
|
||||
->set('name', $updatedDietBeforeToAddDatabase->name)
|
||||
->assertSet('name', $updatedDietBeforeToAddDatabase->name)
|
||||
->set('image', $this->image)
|
||||
->set('duration', $updatedDietBeforeToAddDatabase->duration)
|
||||
->assertSet('duration', $updatedDietBeforeToAddDatabase->duration)
|
||||
->set('state', $updatedDietBeforeToAddDatabase->state)
|
||||
->assertSet('state', $updatedDietBeforeToAddDatabase->state)
|
||||
->set('type', $updatedDietBeforeToAddDatabase->type)
|
||||
->assertSet('type', $updatedDietBeforeToAddDatabase->type)
|
||||
->set('details', $updatedDietBeforeToAddDatabase->details)
|
||||
->assertSet('details', $updatedDietBeforeToAddDatabase->details)
|
||||
->set('daily_schedule', $this->diet->daily_schedule)
|
||||
->assertSet('daily_schedule', $this->diet->daily_schedule)
|
||||
->call('showPreview')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['name', 'image', 'duration', 'state', 'details', 'days', 'type']);
|
||||
|
||||
$updatedDietAfterToAddDatabase = Diet::orderByDesc('id')->first();
|
||||
|
||||
$newDietUrl = route('diet.show', $updatedDietAfterToAddDatabase);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($updatedDietAfterToAddDatabase->image);
|
||||
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($updatedDietBeforeToAddDatabase->name, $updatedDietAfterToAddDatabase->name);
|
||||
self::assertEquals($updatedDietBeforeToAddDatabase->duration, $updatedDietAfterToAddDatabase->duration);
|
||||
self::assertEquals('draft', $updatedDietAfterToAddDatabase->state);
|
||||
self::assertEquals($updatedDietBeforeToAddDatabase->type, $updatedDietAfterToAddDatabase->type);
|
||||
self::assertEquals($updatedDietBeforeToAddDatabase->details, $updatedDietAfterToAddDatabase->details);
|
||||
// self::assertEquals($updatedDietBeforeToAddDatabase->daily_schedule, $updatedDietAfterToAddDatabase->daily_schedule);
|
||||
|
||||
$testCase->assertRedirect($newDietUrl);
|
||||
}
|
||||
|
||||
public function testNothingChange(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$dietUpdate = Livewire::test(Edit::class, [
|
||||
'diet' => $this->diet,
|
||||
])
|
||||
->call('publish')
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['name', 'image', 'duration', 'state', 'details', 'days', 'type']);
|
||||
|
||||
$newDietUrl = route('diet.show', $this->diet, false);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertMissing($dietUpdate->image);
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($this->diet->name, $dietUpdate->name);
|
||||
self::assertEquals($this->diet->duration, $dietUpdate->duration);
|
||||
self::assertEquals($this->diet->state, $dietUpdate->state);
|
||||
self::assertEquals($this->diet->type, $dietUpdate->type);
|
||||
self::assertEquals($this->diet->details, $dietUpdate->details);
|
||||
self::assertEquals($this->diet->daily_schedule, $dietUpdate->days);
|
||||
|
||||
$dietUpdate->assertRedirect($newDietUrl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
31
tests/Feature/Diet/IndexTest.php
Normal file
31
tests/Feature/Diet/IndexTest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Diet;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class IndexTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $user;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
}
|
||||
|
||||
public function test_index_page_success(): void
|
||||
{
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->get(route('plan.index'));
|
||||
|
||||
$response
|
||||
->assertOk();
|
||||
}
|
||||
}
|
||||
31
tests/Feature/Diet/ShowTest.php
Normal file
31
tests/Feature/Diet/ShowTest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Diet;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
use App\Models\Diet;
|
||||
|
||||
class ShowTest extends TestCase
|
||||
{
|
||||
protected User $user;
|
||||
private Diet $diet;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
$this->diet = Diet::inRandomOrder()->first();
|
||||
}
|
||||
|
||||
public function test_show_page_success(): void
|
||||
{
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->get(route('diet.show', $this->diet));
|
||||
|
||||
$response
|
||||
->assertOk();
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,6 @@ class EmailVerificationTest extends TestCase
|
||||
{
|
||||
if (! Features::enabled(Features::emailVerification())) {
|
||||
$this->markTestSkipped('Email verification not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$user = User::factory()->withPersonalTeam()->unverified()->create();
|
||||
@@ -34,8 +32,6 @@ class EmailVerificationTest extends TestCase
|
||||
{
|
||||
if (! Features::enabled(Features::emailVerification())) {
|
||||
$this->markTestSkipped('Email verification not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Event::fake();
|
||||
@@ -60,8 +56,6 @@ class EmailVerificationTest extends TestCase
|
||||
{
|
||||
if (! Features::enabled(Features::emailVerification())) {
|
||||
$this->markTestSkipped('Email verification not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$user = User::factory()->unverified()->create();
|
||||
|
||||
@@ -9,18 +9,20 @@ use Tests\TestCase;
|
||||
class MealFormTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function diary_creation_page_contains_livewire_component()
|
||||
public function diary_creation_page_contains_livewire_component(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
//@var $response
|
||||
$response = $this->followingRedirects()->get(route('diary.index'));
|
||||
$response->assertSeeLivewire('meal-form');
|
||||
// $response->assertSeeLivewire('meal-form');
|
||||
$response->assertSee('meal-form');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function meal_form_productName_is_required()
|
||||
public function meal_form_productName_is_required(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
@@ -44,7 +46,7 @@ class MealFormTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function meal_form_add_portion()
|
||||
public function meal_form_add_portion(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@ class PasswordResetTest extends TestCase
|
||||
{
|
||||
if (! Features::enabled(Features::resetPasswords())) {
|
||||
$this->markTestSkipped('Password updates are not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$response = $this->get('/forgot-password');
|
||||
@@ -30,8 +28,6 @@ class PasswordResetTest extends TestCase
|
||||
{
|
||||
if (! Features::enabled(Features::resetPasswords())) {
|
||||
$this->markTestSkipped('Password updates are not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Notification::fake();
|
||||
@@ -49,8 +45,6 @@ class PasswordResetTest extends TestCase
|
||||
{
|
||||
if (! Features::enabled(Features::resetPasswords())) {
|
||||
$this->markTestSkipped('Password updates are not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Notification::fake();
|
||||
@@ -74,8 +68,6 @@ class PasswordResetTest extends TestCase
|
||||
{
|
||||
if (! Features::enabled(Features::resetPasswords())) {
|
||||
$this->markTestSkipped('Password updates are not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Notification::fake();
|
||||
|
||||
@@ -121,7 +121,7 @@ class CreateTest extends TestCase
|
||||
|
||||
|
||||
$lastCreatedPlan = Plan::orderBy('id', 'desc')->first();
|
||||
$newPlanUrl = route('plan.show', $lastCreatedPlan, false);
|
||||
$newPlanUrl = route('plan.show', $lastCreatedPlan);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($lastCreatedPlan->image);
|
||||
|
||||
@@ -163,7 +163,7 @@ class CreateTest extends TestCase
|
||||
->assertHasNoErrors(['name', 'image', 'duration', 'details']);
|
||||
|
||||
$lastCreatedPlan = Plan::orderBy('id', 'desc')->first();
|
||||
$newPlanUrl = route('plan.show', $lastCreatedPlan, false);
|
||||
$newPlanUrl = route('plan.show', $lastCreatedPlan);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($lastCreatedPlan->image);
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ class EditTest extends TestCase
|
||||
->assertSuccessful()
|
||||
->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']);
|
||||
|
||||
$newPlanUrl = route('plan.show', $this->plan, false);
|
||||
$newPlanUrl = route('plan.show', $this->plan);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertMissing($planUpdate->image);
|
||||
|
||||
|
||||
209
tests/Feature/Product_Nutritional/CreateTest.php
Normal file
209
tests/Feature/Product_Nutritional/CreateTest.php
Normal file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Product_Nutritional;
|
||||
|
||||
use App\Livewire\ProductNutritional\Create;
|
||||
use App\Models\ProductNutritionalValue;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Http\Testing\File;
|
||||
use App\Models\ProductGroup;
|
||||
|
||||
class CreateTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private File $image;
|
||||
|
||||
private ProductNutritionalValue $product;
|
||||
private ProductGroup $product_group;
|
||||
|
||||
protected User $user;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
Storage::fake('tmp-for-tests');
|
||||
$this->image = UploadedFile::fake()->image('product.png');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
$this->product = ProductNutritionalValue::factory()->make();
|
||||
$this->product_group = ProductGroup::inRandomOrder()->first();
|
||||
}
|
||||
|
||||
public function test_show_form_create_product(): void
|
||||
{
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->get(route('product_nutritional_value.create'));
|
||||
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_publish_new_product_success(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$productCountAtStart = ProductNutritionalValue::count();
|
||||
|
||||
$testCase = Livewire::test(Create::class)
|
||||
->set('name', $this->product->name)
|
||||
->assertSet('name', $this->product->name)
|
||||
->set('product_group', $this->product_group->id)
|
||||
->assertSet('product_group', $this->product_group->id)
|
||||
->set('image', $this->image)
|
||||
->set('description', $this->product->description)
|
||||
->assertSet('description', $this->product->description)
|
||||
->set('formulations', $this->product->formulations)
|
||||
->assertSet('formulations', $this->product->formulations)
|
||||
->set('energy_on_100gr', $this->product->energy_on_100gr)
|
||||
->assertSet('energy_on_100gr', $this->product->energy_on_100gr)
|
||||
->set('proteins_on_100gr', $this->product->proteins_on_100gr)
|
||||
->assertSet('proteins_on_100gr', $this->product->proteins_on_100gr)
|
||||
->set('fats_on_100gr', $this->product->fats_on_100gr)
|
||||
->assertSet('fats_on_100gr', $this->product->fats_on_100gr)
|
||||
->set('carbohydrates_on_100gr', $this->product->carbohydrates_on_100gr)
|
||||
->assertSet('carbohydrates_on_100gr', $this->product->carbohydrates_on_100gr)
|
||||
->set('portion_mass_gr', $this->product->portion_mass_gr)
|
||||
->assertSet('portion_mass_gr', $this->product->portion_mass_gr)
|
||||
->set('energy_on_portion', $this->product->energy_on_portion)
|
||||
->assertSet('energy_on_portion', $this->product->energy_on_portion)
|
||||
->set('proteins_on_portion', $this->product->proteins_on_portion)
|
||||
->assertSet('proteins_on_portion', $this->product->proteins_on_portion)
|
||||
->set('fats_on_portion', $this->product->fats_on_portion)
|
||||
->assertSet('fats_on_portion', $this->product->fats_on_portion)
|
||||
->set('carbohydrates_on_portion', $this->product->carbohydrates_on_portion)
|
||||
->assertSet('carbohydrates_on_portion', $this->product->carbohydrates_on_portion)
|
||||
->call('save')
|
||||
->assertSuccessful();
|
||||
// ->assertHasNoErrors([]);
|
||||
|
||||
|
||||
$this->assertEquals($productCountAtStart + 1, ProductNutritionalValue::count());
|
||||
|
||||
$lastCreatedProductNutritionalValue = ProductNutritionalValue::orderByDesc('id')->first();
|
||||
|
||||
$newProductNutritionalValueUrl = route('product_nutritional_value.index');
|
||||
|
||||
$testCase->assertRedirect($newProductNutritionalValueUrl);
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($lastCreatedProductNutritionalValue->image);
|
||||
|
||||
$response = $this->actingAs($this->user)->get(route('product_nutritional_value.index'));
|
||||
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
}
|
||||
|
||||
// public function test_to_draft_new_product_success(): void
|
||||
// {
|
||||
// $this->actingAs($this->user);
|
||||
//
|
||||
// $productCountAtStart = ProductNutritionalValue::count();
|
||||
//
|
||||
// $testCase = Livewire::test(Create::class)
|
||||
// ->set('name', $this->product->name)
|
||||
// ->assertSet('name', $this->product->name)
|
||||
// ->set('image', $this->image)
|
||||
// ->set('duration', $this->product->duration)
|
||||
// ->assertSet('duration', $this->product->duration)
|
||||
// ->set('state', $this->product->state)
|
||||
// ->assertSet('state', $this->product->state)
|
||||
// ->set('type', $this->product->type)
|
||||
// ->assertSet('type', $this->product->type)
|
||||
// ->set('details', $this->product->details)
|
||||
// ->assertSet('details', $this->product->details)
|
||||
// ->set('packets_count', $this->product->packets_count)
|
||||
// ->assertSet('packets_count', $this->product->packets_count)
|
||||
// ->set('packet1_options', $this->product->packet1_options)
|
||||
// ->assertSet('packet1_options', $this->product->packet1_options)
|
||||
// ->set('packet2_options', $this->product->packet2_options)
|
||||
// ->assertSet('packet2_options', $this->product->packet2_options)
|
||||
// ->set('packet3_options', $this->product->packet3_options)
|
||||
// ->assertSet('packet3_options', $this->product->packet3_options)
|
||||
// ->call('addToDrafts')
|
||||
// ->assertSuccessful()
|
||||
// ->assertHasNoErrors(['name', 'image', 'duration', 'details']);
|
||||
//
|
||||
//
|
||||
// $lastCreatedProductNutritionalValue = product::orderBy('id', 'desc')->first();
|
||||
// $newProductNutritionalValueUrl = route('product.show', $lastCreatedproduct, false);
|
||||
//
|
||||
// Storage::disk('tmp-for-tests')->assertExists($lastCreatedProductNutritionalValue->image);
|
||||
//
|
||||
// $testCase->assertRedirect($newProductNutritionalValueUrl);
|
||||
//
|
||||
//
|
||||
// $this->assertEquals($productCountAtStart + 1, ProductNutritionalValue::count());
|
||||
// }
|
||||
//
|
||||
// public function test_to_preview_new_product_success(): void
|
||||
// {
|
||||
// $this->actingAs($this->user);
|
||||
//
|
||||
// $productCountAtStart = ProductNutritionalValue::count();
|
||||
//
|
||||
//
|
||||
// $testCase = Livewire::test(Create::class)
|
||||
// ->set('name', $this->product->name)
|
||||
// ->assertSet('name', $this->product->name)
|
||||
// ->set('image', $this->image)
|
||||
// ->set('duration', $this->product->duration)
|
||||
// ->assertSet('duration', $this->product->duration)
|
||||
// ->set('state', $this->product->state)
|
||||
// ->assertSet('state', $this->product->state)
|
||||
// ->set('type', $this->product->type)
|
||||
// ->assertSet('type', $this->product->type)
|
||||
// ->set('details', $this->product->details)
|
||||
// ->assertSet('details', $this->product->details)
|
||||
// ->set('packets_count', $this->product->packets_count)
|
||||
// ->assertSet('packets_count', $this->product->packets_count)
|
||||
// ->set('packet1_options', $this->product->packet1_options)
|
||||
// ->assertSet('packet1_options', $this->product->packet1_options)
|
||||
// ->set('packet2_options', $this->product->packet2_options)
|
||||
// ->assertSet('packet2_options', $this->product->packet2_options)
|
||||
// ->set('packet3_options', $this->product->packet3_options)
|
||||
// ->assertSet('packet3_options', $this->product->packet3_options)
|
||||
// ->call('showPreview')
|
||||
// ->assertSuccessful()
|
||||
// ->assertHasNoErrors(['name', 'image', 'duration', 'details']);
|
||||
//
|
||||
// $lastCreatedProductNutritionalValue = product::orderBy('id', 'desc')->first();
|
||||
// $newProductNutritionalValueUrl = route('product.show', $lastCreatedproduct, false);
|
||||
//
|
||||
// Storage::disk('tmp-for-tests')->assertExists($lastCreatedProductNutritionalValue->image);
|
||||
//
|
||||
// $testCase->assertRedirect($newProductNutritionalValueUrl);
|
||||
//
|
||||
//
|
||||
// $this->assertEquals($productCountAtStart + 1, ProductNutritionalValue::count());
|
||||
// }
|
||||
//
|
||||
// public function test_set_empty_data(): void
|
||||
// {
|
||||
// $this->actingAs($this->user);
|
||||
//
|
||||
// $productCountAtStart = ProductNutritionalValue::count();
|
||||
//
|
||||
// Livewire::test(Create::class)
|
||||
// ->set('name', null)
|
||||
// ->set('image', null)
|
||||
// ->set('duration', null)
|
||||
// ->set('state', null)
|
||||
// ->set('type', null)
|
||||
// ->set('details', null)
|
||||
// ->set('packets_count', null)
|
||||
// ->set('packet1_options', null)
|
||||
// ->set('packet2_options', null)
|
||||
// ->set('packet3_options', null)
|
||||
// ->call('publish')
|
||||
// ->assertHasErrors(['name', 'image', 'details']);
|
||||
//
|
||||
// $this->assertEquals($productCountAtStart, ProductNutritionalValue::count());
|
||||
// }
|
||||
// }
|
||||
105
tests/Feature/Product_Nutritional/EditTest.php
Normal file
105
tests/Feature/Product_Nutritional/EditTest.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Product_Nutritional;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
use App\Livewire\ProductNutritional\Edit;
|
||||
use App\Models\ProductNutritionalValue;
|
||||
use App\Models\ProductGroup;
|
||||
|
||||
class EditTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private UploadedFile $image;
|
||||
|
||||
private ProductNutritionalValue $product;
|
||||
private ProductGroup $product_group;
|
||||
|
||||
protected User $user;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
Storage::fake('tmp-for-tests');
|
||||
|
||||
$this->image = UploadedFile::fake()->image('product.png');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
|
||||
$this->product = ProductNutritionalValue::factory()->make();
|
||||
$this->product->product_group()->associate($product_group = ProductGroup::inRandomOrder()->first());
|
||||
$this->product->saveOrFail();
|
||||
|
||||
$this->product_group = $product_group;
|
||||
}
|
||||
|
||||
public function test_show_form_edit_product(): void
|
||||
{
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->get(route('product_nutritional_value.edit', $this->product));
|
||||
|
||||
$response->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_publish_new_product_success(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$updatedProductBeforeToAddDatabase = ProductNutritionalValue::factory()->make();
|
||||
|
||||
$testCase = Livewire::test(Edit::class, [
|
||||
'product' => $this->product,
|
||||
])
|
||||
->set('name', $updatedProductBeforeToAddDatabase->name)
|
||||
->assertSet('name', $updatedProductBeforeToAddDatabase->name)
|
||||
->set('product_group', $this->product_group->id)
|
||||
->assertSet('product_group', $this->product_group->id)
|
||||
->set('image', $this->image)
|
||||
->set('description', $updatedProductBeforeToAddDatabase->description)
|
||||
->assertSet('description', $updatedProductBeforeToAddDatabase->description)
|
||||
->set('formulations', $updatedProductBeforeToAddDatabase->formulations)
|
||||
->assertSet('formulations', $updatedProductBeforeToAddDatabase->formulations)
|
||||
->set('energy_on_100gr', $updatedProductBeforeToAddDatabase->energy_on_100gr)
|
||||
->assertSet('energy_on_100gr', $updatedProductBeforeToAddDatabase->energy_on_100gr)
|
||||
->set('proteins_on_100gr', $updatedProductBeforeToAddDatabase->proteins_on_100gr)
|
||||
->assertSet('proteins_on_100gr', $updatedProductBeforeToAddDatabase->proteins_on_100gr)
|
||||
->set('fats_on_100gr', $updatedProductBeforeToAddDatabase->fats_on_100gr)
|
||||
->assertSet('fats_on_100gr', $updatedProductBeforeToAddDatabase->fats_on_100gr)
|
||||
->set('carbohydrates_on_100gr', $updatedProductBeforeToAddDatabase->carbohydrates_on_100gr)
|
||||
->assertSet('carbohydrates_on_100gr', $updatedProductBeforeToAddDatabase->carbohydrates_on_100gr)
|
||||
->set('portion_mass_gr', $updatedProductBeforeToAddDatabase->portion_mass_gr)
|
||||
->assertSet('portion_mass_gr', $updatedProductBeforeToAddDatabase->portion_mass_gr)
|
||||
->set('energy_on_portion', $updatedProductBeforeToAddDatabase->energy_on_portion)
|
||||
->assertSet('energy_on_portion', $updatedProductBeforeToAddDatabase->energy_on_portion)
|
||||
->set('proteins_on_portion', $updatedProductBeforeToAddDatabase->proteins_on_portion)
|
||||
->assertSet('proteins_on_portion', $updatedProductBeforeToAddDatabase->proteins_on_portion)
|
||||
->set('fats_on_portion', $updatedProductBeforeToAddDatabase->fats_on_portion)
|
||||
->assertSet('fats_on_portion', $updatedProductBeforeToAddDatabase->fats_on_portion)
|
||||
->set('carbohydrates_on_portion', $updatedProductBeforeToAddDatabase->carbohydrates_on_portion)
|
||||
->assertSet('carbohydrates_on_portion', $updatedProductBeforeToAddDatabase->carbohydrates_on_portion)
|
||||
->call('save')
|
||||
->assertSuccessful();
|
||||
|
||||
$updatedProductAfterToAddDatabase = ProductNutritionalValue::orderByDesc('id')->first();
|
||||
|
||||
$newproductUrl = route('product_nutritional_value.index');
|
||||
|
||||
Storage::disk('tmp-for-tests')->assertExists($updatedProductAfterToAddDatabase->image);
|
||||
|
||||
|
||||
// check data after update recipe
|
||||
self::assertEquals($updatedProductBeforeToAddDatabase->name, $updatedProductAfterToAddDatabase->name);
|
||||
self::assertEquals($updatedProductBeforeToAddDatabase->description, $updatedProductAfterToAddDatabase->description);
|
||||
self::assertEquals($updatedProductBeforeToAddDatabase->formulations, $updatedProductAfterToAddDatabase->formulations);
|
||||
|
||||
$testCase->assertRedirect($newproductUrl);
|
||||
}
|
||||
}
|
||||
35
tests/Feature/Product_Nutritional/IndexTest.php
Normal file
35
tests/Feature/Product_Nutritional/IndexTest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Product_Nutritional;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
use App\Models\ProductNutritionalValue;
|
||||
|
||||
class IndexTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public ProductNutritionalValue $product;
|
||||
|
||||
protected User $user;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
$this->product = ProductNutritionalValue::inRandomOrder()->first();
|
||||
}
|
||||
|
||||
public function test_index_page_success(): void
|
||||
{
|
||||
$response = $this
|
||||
->actingAs($this->user)
|
||||
->get(route('product_nutritional_value.index'));
|
||||
|
||||
$response
|
||||
->assertOk();
|
||||
}
|
||||
}
|
||||
47
tests/Feature/Product_Nutritional/ShowTest.php
Normal file
47
tests/Feature/Product_Nutritional/ShowTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Product_Nutritional;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
use App\Models\ProductNutritionalValue;
|
||||
|
||||
class ShowTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private ProductNutritionalValue $product;
|
||||
|
||||
protected User $user;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->refreshApplicationWithLocale('en');
|
||||
|
||||
$this->user = User::factory()->create(['is_consultant' => true]);
|
||||
$this->product = ProductNutritionalValue::inRandomOrder()->first();
|
||||
}
|
||||
|
||||
public function test_show_page_success(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->get(route('product_nutritional_value.show', $this->product));
|
||||
|
||||
$response
|
||||
->assertOk();
|
||||
}
|
||||
|
||||
// When appear role for user
|
||||
// public function test_show_form_is_not_consultant()
|
||||
// {
|
||||
// $user = User::factory()->create(['is_consultant' => false]);
|
||||
|
||||
// $response = $this->actingAs($this->user)
|
||||
// ->get('/plan/'. $this->plan->id);
|
||||
|
||||
// $response
|
||||
// ->assertStatus(403);
|
||||
|
||||
// }
|
||||
}
|
||||
@@ -16,10 +16,11 @@ class ProfileInformationTest extends TestCase
|
||||
{
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
/** @var UpdateProfileInformationForm $component */
|
||||
$component = Livewire::test(UpdateProfileInformationForm::class);
|
||||
|
||||
$this->assertEquals($user->name, $component->state['name']);
|
||||
$this->assertEquals($user->email, $component->state['email']);
|
||||
self::assertEquals($user->name, $component->state['name']);
|
||||
self::assertEquals($user->email, $component->state['email']);
|
||||
}
|
||||
|
||||
public function test_profile_information_can_be_updated(): void
|
||||
|
||||
@@ -17,7 +17,7 @@ class RegistrationTest extends TestCase
|
||||
if (! Features::enabled(Features::registration())) {
|
||||
$this->markTestSkipped('Registration support is not enabled.');
|
||||
|
||||
return;
|
||||
// return;
|
||||
}
|
||||
|
||||
$response = $this->get('/register');
|
||||
@@ -30,7 +30,7 @@ class RegistrationTest extends TestCase
|
||||
if (Features::enabled(Features::registration())) {
|
||||
$this->markTestSkipped('Registration support is enabled.');
|
||||
|
||||
return;
|
||||
// return;
|
||||
}
|
||||
|
||||
$response = $this->get('/register');
|
||||
@@ -43,7 +43,7 @@ class RegistrationTest extends TestCase
|
||||
if (! Features::enabled(Features::registration())) {
|
||||
$this->markTestSkipped('Registration support is not enabled.');
|
||||
|
||||
return;
|
||||
// return;
|
||||
}
|
||||
|
||||
$response = $this->post('/register', [
|
||||
|
||||
@@ -17,8 +17,6 @@ class TwoFactorAuthenticationSettingsTest extends TestCase
|
||||
{
|
||||
if (! Features::canManageTwoFactorAuthentication()) {
|
||||
$this->markTestSkipped('Two factor authentication is not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
@@ -38,8 +36,6 @@ class TwoFactorAuthenticationSettingsTest extends TestCase
|
||||
{
|
||||
if (! Features::canManageTwoFactorAuthentication()) {
|
||||
$this->markTestSkipped('Two factor authentication is not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
@@ -62,8 +58,6 @@ class TwoFactorAuthenticationSettingsTest extends TestCase
|
||||
{
|
||||
if (! Features::canManageTwoFactorAuthentication()) {
|
||||
$this->markTestSkipped('Two factor authentication is not enabled.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
@@ -27,7 +27,7 @@ abstract class TestCase extends BaseTestCase
|
||||
->create();
|
||||
}
|
||||
|
||||
protected function refreshApplicationWithLocale($locale)
|
||||
protected function refreshApplicationWithLocale(string $locale): void
|
||||
{
|
||||
self::tearDown();
|
||||
putenv(LaravelLocalization::ENV_ROUTE_KEY.'='.$locale);
|
||||
|
||||
Reference in New Issue
Block a user