Merge pull request 'main' (#14) from eatvio/eatvio:main into main

Reviewed-on: apoloz/eatvio#14
This commit is contained in:
apoloz
2024-01-15 12:06:05 +00:00
100 changed files with 1655 additions and 735 deletions

View File

@@ -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
{

View File

@@ -4,6 +4,7 @@ namespace App\Console\Commands;
use App\Models\Recipe;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
class UpdateSlugs extends Command
{
@@ -24,7 +25,7 @@ class UpdateSlugs extends Command
/**
* Execute the console command.
*/
public function handle()
public function handle(): void
{
Recipe::where('slug', '')
->get()

View File

@@ -12,7 +12,7 @@ class ChatMessageUpdated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
public array $message;
/**
* Create a new event instance.

View File

@@ -12,9 +12,9 @@ class DietSelected
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $diet;
public Diet $diet;
public $user;
public User $user;
/**
* Create a new event instance.

View File

@@ -11,19 +11,19 @@ use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
class CalendarController extends Controller
{
public $weekStartsAt;
public int $weekStartsAt;
public $weekEndsAt;
public int $weekEndsAt;
public $startsAt;
public Carbon $startsAt;
public $endsAt;
public Carbon $endsAt;
public $gridStartsAt;
public Carbon $gridStartsAt;
public $gridEndsAt;
public Carbon $gridEndsAt;
public function __construct($initialYear = null, $initialMonth = 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
@@ -38,7 +38,7 @@ class CalendarController extends Controller
$this->calculateGridStartsEnds();
}
public function calculateGridStartsEnds()
public function calculateGridStartsEnds(): void
{
$this->gridStartsAt = $this->startsAt->clone()->startOfWeek($this->weekStartsAt);
$this->gridEndsAt = $this->endsAt->clone()->endOfWeek($this->weekEndsAt);
@@ -53,7 +53,7 @@ class CalendarController extends Controller
$this->gridEndsAt
);
$filledDays = Diary::where('user_id', $curUser->id)
->whereMonth('date', now()->month)
->whereMonth('date', (string) now()->month)
->get()
->keyBy('date');

View File

@@ -2,28 +2,27 @@
namespace App\Http\Controllers;
use App\Events\ChatMessageUpdated;
use App\Models\Chat;
use App\Models\User;
use Illuminate\View\View;
class ChatMessage
{
public $id;
public int $id;
public $payload;
public int $payload;
public function __construct($id, $payload)
public function __construct(int $id, int $payload)
{
$this->id = $id;
$this->payload = $payload;
}
public function someRandomFillFunction()
public function someRandomFillFunction(): void
{
$users1 = User::all()->pluck('id');
$users2 = User::all()->pluck('id');
$faker = Faker\Factory::create();
$faker = \Faker\Factory::create();
$users1->each(
function ($user1, $key) use ($faker, $users2) {
@@ -94,11 +93,11 @@ class ChatController extends Controller
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
* // * @return \Illuminate\Http\Response
*/
public function create()
public function create(): void
{
ChatMessageUpdated::dispatch(new ChatMessage(time(), 'some text '.md5(time())));
// ChatMessageUpdated::dispatch(new ChatMessage(time(), 'some text '.md5(time())));
}
public function show(int $lastChatUser): View
@@ -129,7 +128,7 @@ class ChatController extends Controller
);
}
private function makeChanName($from, $to)
private function makeChanName(?int $from = null, ?int $to = null): string
{
return (int) $from < (int) $to
? $from.'_'.$to

View File

@@ -32,7 +32,7 @@ class DiaryController extends Controller
return view('diary.show', ['curDiary' => $diary, 'daysCount' => $daysCount]);
}
public function edit($id): View
public function edit(int $id): View
{
$curDiary = Diary::find($id);
$daysCount = Diary::where('user_id', auth()->id())->count();
@@ -47,7 +47,7 @@ class DiaryController extends Controller
);
}
public function update(Request $request, $id): RedirectResponse
public function update(Request $request, int $id): RedirectResponse
{
/* dd($request, $id, $request->input()); */
$curDiary = Diary::find($id);

View File

@@ -7,66 +7,31 @@ use Illuminate\Http\Request;
class FinanceController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
public function index(): void
{
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
public function create(): void
{
}
/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(Request $request): void
{
}
/**
* Display the specified resource.
*
* @return \Illuminate\Http\Response
*/
public function show(Finance $finance)
public function show(Finance $finance): void
{
}
/**
* Show the form for editing the specified resource.
*
* @return \Illuminate\Http\Response
*/
public function edit(Finance $finance)
public function edit(Finance $finance): void
{
}
/**
* Update the specified resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Finance $finance)
public function update(Request $request, Finance $finance): void
{
}
/**
* Remove the specified resource from storage.
*
* @return \Illuminate\Http\Response
*/
public function destroy(Finance $finance)
public function destroy(Finance $finance): void
{
}
}

View File

@@ -2,9 +2,11 @@
namespace App\Http\Controllers;
use Illuminate\Http\RedirectResponse;
class RegistrationStartController extends Controller
{
public function start()
public function start(): RedirectResponse
{
session()->flush();

View File

@@ -8,67 +8,32 @@ use Illuminate\Http\Request;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
public function index(): void
{
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
public function create(): void
{
}
/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(Request $request): void
{
}
/**
* Display the specified resource.
*
* @return \Illuminate\Http\Response
*/
public function show(User $user)
public function show(User $user): void
{
/* return view('user.show', ['user' => $user]); */
}
/**
* Show the form for editing the specified resource.
*
* @return \Illuminate\Http\Response
*/
public function edit(UserDetailz $userDetailz)
public function edit(UserDetailz $userDetailz): void
{
}
/**
* Update the specified resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function update(Request $request, UserDetailz $userDetailz)
public function update(Request $request, UserDetailz $userDetailz): void
{
}
/**
* Remove the specified resource from storage.
*
* @return \Illuminate\Http\Response
*/
public function destroy(UserDetailz $userDetailz)
public function destroy(UserDetailz $userDetailz): void
{
}
}

View File

@@ -12,14 +12,9 @@ class ProcessDietSelectedNotification implements ShouldQueue
{
use InteractsWithQueue;
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;

View File

@@ -2,24 +2,26 @@
namespace App\Livewire\Chat;
use Illuminate\Support\Collection;
use Illuminate\View\View;
use Livewire\Component;
class LastUsers extends Component
{
public $lastChatUsers;
public Collection $lastChatUsers;
public $activeUserId;
public int|null $activeUserId = null;
public $curUserId;
public int $curUserId;
public $chanId;
public string $chanId;
public function render()
public function render(): View
{
return view('livewire.chat.last-users');
}
public function switchTo($id)
public function switchTo(int $id): void
{
$this->activeUserId = $id;
$this->dispatch('updateRecipientId', id: $id)->to('chat.message-window');

View File

@@ -5,25 +5,27 @@ namespace App\Livewire\Chat;
use App\Events\ChatMessageUpdated;
use App\Models\Chat;
use App\Models\User;
use Illuminate\Support\Collection;
use Illuminate\View\View;
use Livewire\Component;
class MessageWindow extends Component
{
public $messages = [];
public array|Collection $messages = [];
public $curMessage = '';
public string $curMessage = '';
public $curUserId;
public int $curUserId;
public $recipientUserId;
public int|null $recipientUserId = null;
public $recipientUser;
public User|null $recipientUser = null;
public $chanId;
public string $chanId;
public $curUser;
public User $curUser;
public function getListeners()
public function getListeners(): array
{
return [
'echo-private:direct-chat.'.$this->chanId.',ChatMessageUpdated' => 'notifyNewMessage',
@@ -33,7 +35,7 @@ class MessageWindow extends Component
];
}
public function notifyNewMessage($e): void
public function notifyNewMessage(array $e): void
{
$message = $e['message'];
@@ -41,11 +43,11 @@ class MessageWindow extends Component
->prepend($message);
}
public function updateRecipientId($id = null)
public function updateRecipientId(?int $id = null): void
{
}
public function whisperTypeing()
public function whisperTypeing(): void
{
$this->dispatch(
'typing',
@@ -58,7 +60,7 @@ class MessageWindow extends Component
}
// FIXME
public function mount($recipientUserId)
public function mount(?int $recipientUserId = null): void
{
$this->recipientUserId = $recipientUserId;
$this->recipientUser = User::find($recipientUserId);
@@ -74,12 +76,12 @@ class MessageWindow extends Component
}
}
public function render()
public function render(): View
{
return view('livewire.chat.message-window');
}
public function sendChatMessage()
public function sendChatMessage(): void
{
$chatMessage = [
'data' => $this->curMessage,

View File

@@ -2,25 +2,28 @@
namespace App\Livewire\Chat;
use Illuminate\View\View;
use Livewire\Component;
class Tracker extends Component
{
public $showNewMessageNotifycation = false;
public int|bool $showNewMessageNotifycation = false;
public $myMessages = [];
public array $myMessages = [];
// Special Syntax: ['echo:{channel},{event}' => '{method}']
protected $listeners = ['echo:direct-chat,ChatMessageUpdated' => 'notifyNewMessage'];
public function notifyNewMessage($payload): void
public function notifyNewMessage(string $payload): void
{
$this->myMessages[] = $payload;
$this->showNewMessageNotifycation = true;
}
public function render()
public function render(): View
{
return view('livewire.chat.tracker');
}
protected function getListeners(): array
{
return ['echo:direct-chat,ChatMessageUpdated' => 'notifyNewMessage'];
}
}

View File

@@ -3,11 +3,12 @@
namespace App\Livewire\Consultant;
use App\Models\ConsultantEducation;
use Illuminate\View\View;
use Livewire\Component;
class ListConsultants extends Component
{
public function render()
public function render(): View
{
return view(
'livewire.consultant.list-consultants',

View File

@@ -6,8 +6,10 @@ use App\Models\ConsultantEducation;
use App\Models\User;
use App\Models\UserAttachment;
use App\Notifications\ConsultantRequestStarted;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithFileUploads;
@@ -27,15 +29,15 @@ class RegistrationForm extends Component
public string $telegramLink = '';
public bool $hasMedicalEducation = false;
public bool|int $hasMedicalEducation = false;
public $certPhotos = [];
public array|Collection $certPhotos = [];
public $tmpCertPhotos = [];
public array $tmpCertPhotos = [];
public string $legalType = 'selfemployed';
protected $rules = [
protected array $rules = [
'medicalEducations.*.title' => 'required|string|min:6',
'medicalEducations.*.date' => 'required|date',
'vkLink' => 'required|url',
@@ -46,7 +48,7 @@ class RegistrationForm extends Component
'tmpCertPhotos.*' => 'image|max:4024',
];
public function mount()
public function mount(): void
{
$this->user = Auth::user();
$consultant_request = $this->user->consultant_request;
@@ -61,17 +63,17 @@ class RegistrationForm extends Component
$photos = $this->user->attachments()->certs()->get();
if ($photos) {
$this->certPhotos = collect($photos);
}
// if ($photos) {
$this->certPhotos = collect($photos);
// }
}
public function render()
public function render(): View
{
return view('livewire.consultant.registration-form');
}
public function addEducation()
public function addEducation(): void
{
$this->validate();
$medicalEducations = $this->medicalEducations;
@@ -91,7 +93,7 @@ class RegistrationForm extends Component
$this->medicalEducations = $medicalEducations;
}
public function remove($index)
public function remove(string $index): void
{
$filteredEducations = array_filter(
$this->medicalEducations,
@@ -104,7 +106,7 @@ class RegistrationForm extends Component
$this->medicalEducations = array_values($filteredEducations);
}
public function save()
public function save(): void
{
$data = [
'user_id' => $this->user->id,
@@ -131,7 +133,7 @@ class RegistrationForm extends Component
$attachmentGroup = 'user_certs';
foreach ($this->tmpCertPhotos as $photo) {
$curCert = $photo->storePublicly('public/'.$attachmentGroup.'/'.$this->user->id);
$curCert = $photo->storePublicly('public/' . $attachmentGroup . '/' . $this->user->id);
$fileData = [
'user_id' => $this->user->id,
'group' => $attachmentGroup,
@@ -142,7 +144,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(),
@@ -158,7 +160,7 @@ class RegistrationForm extends Component
$this->user->notify(new ConsultantRequestStarted($consultantEducation));
}
public function deleteImg($id)
public function deleteImg(int $id): void
{
$file = UserAttachment::find($id);
$fileSpecs = json_decode($file->specs, true);

View File

@@ -2,23 +2,24 @@
namespace App\Livewire;
use Illuminate\View\View;
use Livewire\Component;
class Counter extends Component
{
public $count = 0;
public int $count = 0;
public function inc()
public function inc(): void
{
$this->count++;
}
public function dec()
public function dec(): void
{
$this->count--;
}
public function render()
public function render(): View
{
return view('livewire.counter');
}

View File

@@ -3,36 +3,39 @@
namespace App\Livewire\Diary;
use App\Models\ConsultantDiaryComment;
use App\Models\Diary;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use Livewire\Component;
class ConsultantCommentsEdit extends Component
{
public $daysCount;
public int $daysCount;
public $diary;
public Diary $diary;
public $curMeals;
public array|Collection $curMeals = [];
public $typeNames;
public array $typeNames;
public $comments = [];
public array $comments = [];
public $retireComment = '';
public string $retireComment = '';
public $breakfastComment = '';
public string $breakfastComment = '';
public $dinnerComment = '';
public string $dinnerComment = '';
public $supperComment = '';
public string $supperComment = '';
public $lunchComment = '';
public string $lunchComment = '';
public $snacksComment = '';
public string $snacksComment = '';
public $totalComment = '';
public string $totalComment = '';
public function mount()
public function mount(): void
{
$this->comments = (new ConsultantDiaryComment())->where(
'user_id',
@@ -43,7 +46,7 @@ class ConsultantCommentsEdit extends Component
)->pluck('comment', 'comment_type')->toArray();
}
public function render()
public function render(): View
{
$commentTypes = ['breakfast', 'dinner', 'supper', 'lunch', 'snacks', 'wakeup_time', 'total'];
@@ -55,7 +58,7 @@ class ConsultantCommentsEdit extends Component
);
}
public function save()
public function save(): void
{
foreach ($this->comments as $key => $comment) {
$updateComment = ConsultantDiaryComment::updateOrCreate(

View File

@@ -5,6 +5,7 @@ namespace App\Livewire\Diary;
use App\Models\Meal;
use App\Models\UserAttachment;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithFileUploads;
@@ -14,9 +15,9 @@ class MealPhotos extends Component
public Meal $meal;
public $tmpMealPhotos = [];
public array $tmpMealPhotos = [];
public function render()
public function render(): View
{
return view(
'livewire.diary.meal-photos',
@@ -26,7 +27,7 @@ class MealPhotos extends Component
);
}
public function updatedTmpMealPhotos($values)
public function updatedTmpMealPhotos(array $values): void
{
/* dd($values); */
$newPhotos = collect($values)->take(3);

View File

@@ -5,6 +5,7 @@ namespace App\Livewire\Diet\Comment;
use App\Models\Diet;
use App\Models\DietComment;
use App\Models\User;
use Illuminate\View\View;
use Livewire\Component;
class Create extends Component
@@ -13,23 +14,23 @@ class Create extends Component
public User $user;
public $body = '';
public string $body = '';
public $grade = 0;
public string|int $grade = 0;
public $isChecked = true;
public bool $isChecked = true;
public function render()
public function render(): View
{
return view('livewire.diet.comment.create');
}
public function toggle()
public function toggle(): void
{
$this->isChecked ? false : true;
}
public function save()
public function save(): void
{
$this->toggle();
$comment = new DietComment();

View File

@@ -3,16 +3,20 @@
namespace App\Livewire\Diet\Comment;
use App\Models\Diet;
use Illuminate\View\View;
use Livewire\Component;
class Show extends Component
{
public Diet $diet;
protected $listeners = ['commentAdded' => '$refresh'];
public function render()
public function render(): View
{
return view('livewire.diet.comment.show');
}
protected function getListeners(): array
{
return ['commentAdded' => '$refresh'];
}
}

View File

@@ -3,18 +3,19 @@
namespace App\Livewire\Diet\Comment;
use App\Models\DietComment;
use Illuminate\View\View;
use Livewire\Component;
class Upvote extends Component
{
public DietComment $comment;
public function mount(DietComment $comment)
public function mount(DietComment $comment): void
{
$this->comment = $comment;
}
public function render()
public function render(): View
{
$upvotes = $this->comment->upvotes()->forDietCommentsUpVote($this->comment)->count();
$downvotes = $this->comment->upvotes()->forDietCommentsDownVote($this->comment)->count();
@@ -30,7 +31,7 @@ class Upvote extends Component
);
}
public function upvote()
public function upvote(): void
{
if ($this->comment->isUpVoted()) {
$this->comment->removeUpVote();
@@ -49,7 +50,7 @@ class Upvote extends Component
]);
}
public function downvote()
public function downvote(): void
{
if ($this->comment->isDownVoted()) {
$this->comment->removeDownVote();

View File

@@ -3,7 +3,9 @@
namespace App\Livewire\Diet;
use App\Models\Diet;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithFileUploads;
@@ -11,86 +13,92 @@ class Create extends Component
{
use WithFileUploads;
public $name = '';
public string $name = '';
public $image;
public UploadedFile|null $image = null;
public $duration = '7';
public int|string $duration = '7';
public $state = 'draft';
public string $state = 'draft';
public $type = [];
public array $type = [];
public $details = '';
public string $details = '';
public $days = [];
public array $days = [];
public $copyedDay;
public string $copyedDay;
public $copyedDayData;
public array $copyedDayData;
protected $listeners = ['dayUpdated', 'makeCopy', 'makePaste'];
public function render()
public function render(): View
{
return view('livewire.diet.create');
}
public function dayUpdated($dayIndex, $data)
public function dayUpdated(string $dayIndex, array $data): void
{
$this->days[$dayIndex] = $data;
}
public function showPreview()
public function showPreview(): void
{
$this->state = 'draft';
$this->publish();
}
public function addToDrafts()
public function addToDrafts(): void
{
$this->state = 'draft';
$this->publish();
}
public function makeCopy($day)
public function makeCopy(string $day): void
{
$this->copyedDay = $day;
}
public function makePaste($copyToDay)
public function makePaste(string $copyToDay): void
{
$data = $this->days[$this->copyedDay];
$this->dispatch('takePaste', day: $copyToDay, data: $data)->to('diet.day-edit');
}
public function publish()
public function publish(): void
{
$this->validate();
$diet = new Diet();
$diet->name = $this->name;
$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);
// return redirect()->route('diet.show', $diet->id);
}
protected function rules()
protected function getListeners(): array
{
return ['dayUpdated', 'makeCopy', 'makePaste'];
}
protected function rules(): array
{
return [
'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',
];

View File

@@ -2,38 +2,37 @@
namespace App\Livewire\Diet;
use Illuminate\View\View;
use Livewire\Component;
class DayEdit extends Component
{
public $day;
public string $day;
public $eatingTypes = ['breakfast', 'dinner', 'supper', 'lunch', 'snacks'];
public array $eatingTypes = ['breakfast', 'dinner', 'supper', 'lunch', 'snacks'];
public $activeType = 'breakfast';
public string $activeType = 'breakfast';
public $portions = [];
public array $portions = [];
public $name = '';
public string $name = '';
public $quantity = 0;
public int $quantity = 0;
public $portion = 'gram';
public string $portion = 'gram';
protected $listeners = ['takePaste'];
protected $rules = [
protected array $rules = [
'name' => 'required|min:3',
'quantity' => 'required|numeric|min:1',
'portion' => 'required|min:3',
];
public function render()
public function render(): View
{
return view('livewire.diet.day-edit');
}
public function addPortion($type)
public function addPortion(string $type): void
{
$this->validate();
$newData = [
@@ -49,7 +48,7 @@ class DayEdit extends Component
$this->dispatch('dayUpdated', dayIndex: $this->day, data: $this->portions);
}
public function delete($uniq, $type)
public function delete(string $uniq, string $type): void
{
$newPortions = collect($this->portions[$type])
->filter(
@@ -61,7 +60,7 @@ class DayEdit extends Component
$this->dispatch('dayUpdated', dayIndex: $this->day, data: $this->portions);
}
public function edit($uniq, $type)
public function edit(string $uniq, string $type): void
{
$elemKey = collect($this->portions[$type])
->search(function ($item) use ($uniq) {
@@ -80,7 +79,7 @@ class DayEdit extends Component
}
}
public function takePaste($day, $data)
public function takePaste(string $day, array $data): void
{
if (intval($day) === intval($this->day)) {
foreach ($data as $type => $props) {
@@ -89,4 +88,9 @@ class DayEdit extends Component
$this->dispatch('dayUpdated', dayIndex: $this->day, data: $this->portions);
}
}
protected function getListeners(): array
{
return ['takePaste'];
}
}

View File

@@ -3,72 +3,75 @@
namespace App\Livewire\Diet;
use App\Models\Diet;
use Illuminate\Http\UploadedFile;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithFileUploads;
class Edit extends Component
{
use WithFileUploads;
public Diet $diet;
public $name = '';
public string $name = '';
public $image;
public UploadedFile|string $image = '';
public $duration = '7';
public int|string $duration = '7';
public $state = 'draft';
public string $state = 'draft';
public $type = [];
public array $type = [];
public $details = '';
public string $details = '';
public $days = [];
public array $days = [];
public $copyedDay;
public string $copyedDay;
public $copyedDayData;
public array $copyedDayData;
protected $listeners = ['dayUpdated', 'makeCopy', 'makePaste'];
public function mount(Diet $diet)
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()
public function render(): View
{
return view('livewire.diet.edit');
}
public function dayUpdated($dayIndex, $data)
public function dayUpdated(string $dayIndex, array $data): void
{
$this->days[$dayIndex] = $data;
}
public function showPreview()
public function showPreview(): void
{
$this->state = 'draft';
$this->publish();
}
public function addToDrafts()
public function addToDrafts(): void
{
$this->state = 'draft';
$this->publish();
}
public function makeCopy($day)
public function makeCopy(string $day): void
{
/* dd($day); */
$this->copyedDay = $day;
}
public function makePaste($copyToDay)
public function makePaste(string $copyToDay): void
{
$data = $this->days[$this->copyedDay];
$this->dispatch(
@@ -78,7 +81,7 @@ class Edit extends Component
)->to('diet.day-edit');
}
public function publish()
public function publish(): void
{
$this->validate();
@@ -86,26 +89,32 @@ 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();
$this->redirectRoute('diet.show', $diet);
/* $user = Auth::user(); */
/* $user->author_of_diets()->attach($diet->id); */
return redirect()->route('diet.show', $diet->id);
}
protected function rules()
protected function getListeners(): array
{
return ['dayUpdated', 'makeCopy', 'makePaste'];
}
protected function rules(): array
{
return [
'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',
];

View File

@@ -3,20 +3,21 @@
namespace App\Livewire\Diet;
use App\Models\Diet;
use Illuminate\View\View;
use Livewire\Component;
class Like extends Component
{
public Diet $diet;
public $isIconOnly = false;
public bool $isIconOnly = false;
public function mount(Diet $diet)
public function mount(Diet $diet): void
{
$this->diet = $diet;
}
public function render()
public function render(): View
{
return view('livewire.diet.like');
}

View File

@@ -5,6 +5,7 @@ namespace App\Livewire\Diet;
use App\Events\DietSelected;
use App\Models\Diet;
use App\Models\User;
use Illuminate\View\View;
use Livewire\Component;
class StartButton extends Component
@@ -13,19 +14,19 @@ class StartButton extends Component
public User $user;
public $chosenDietState;
public string $chosenDietState;
public function mount()
public function mount(): void
{
$this->chosenDietState = data_get($this->user->chosen_diet, 'last_state', 'oops');
}
public function render()
public function render(): View
{
return view('livewire.diet.start-button');
}
public function start()
public function start(): void
{
DietSelected::dispatch(
$this->diet,
@@ -33,7 +34,7 @@ class StartButton extends Component
);
}
public function getLastState()
public function getLastState(): void
{
$this->chosenDietState = data_get($this->user->chosen_diet, 'last_state', 'oops');
}

View File

@@ -2,13 +2,14 @@
namespace App\Livewire\Feed;
use Illuminate\View\View;
use Livewire\Component;
class Index extends Component
{
public $posts;
public array $posts;
public function render()
public function render(): View
{
return view('livewire.feed.index');
}

View File

@@ -11,75 +11,75 @@ class ProfileEditDetailzForm extends Form
public ?UserDetailz $userDetailz;
#[Rule('required|string|min:3')]
public $first_name;
public string $first_name;
#[Rule('required|string|min:3')]
public $last_name;
public string $last_name;
#[Rule('required|email')]
public $email;
public string $email;
#[Rule('required|in:male,female')]
public $gender;
public string $gender;
#[Rule('required|date')]
public $birthdate;
public string $birthdate;
#[Rule('required|string|min:3')]
public $country;
public string $country;
#[Rule('required|string|min:3')]
public $city;
public string $city;
#[Rule('required|string|min:3')]
public $lang;
public string $lang;
#[Rule('required|integer|min:35')]
public $weight;
public int $weight;
#[Rule('required|integer|min:35')]
public $height;
public int $height;
#[Rule('required|integer|min:20')]
public $chest_circumference;
public int $chest_circumference;
#[Rule('required|integer|min:20')]
public $waist_circumference;
public int $waist_circumference;
#[Rule('required|integer|min:20')]
public $hip_circumference;
public int $hip_circumference;
#[Rule('required|integer|min:20')]
public $blood_pressure_up;
public int $blood_pressure_up;
#[Rule('required|integer|min:20')]
public $blood_pressure_down;
public int $blood_pressure_down;
#[Rule('required|boolean')]
public $has_hypo;
public int|bool $has_hypo;
#[Rule('required|boolean')]
public $has_hyper;
public int|bool $has_hyper;
#[Rule('nullable')]
public $about_alergy = 'nullable';
public string $about_alergy = 'nullable';
#[Rule('nullable')]
public $about_taking_pils = 'nullable';
public string $about_taking_pils = 'nullable';
#[Rule('nullable')]
public $about_sport_hobbies = 'nullable';
public string $about_sport_hobbies = 'nullable';
#[Rule('nullable')]
public $favorite_foods = 'nullable';
public string $favorite_foods = 'nullable';
#[Rule('nullable')]
public $unfavorite_foods = 'nullable';
public string $unfavorite_foods = 'nullable';
#[Rule('nullable')]
public $additional_info = 'nullable';
public string $additional_info = 'nullable';
public function setDetailz(UserDetailz $detailz)
public function setDetailz(UserDetailz $detailz): void
{
$this->userDetailz = $detailz;
$this->first_name = $detailz->first_name;
@@ -107,7 +107,7 @@ class ProfileEditDetailzForm extends Form
$this->additional_info = $detailz->additional_info;
}
public function update()
public function update(): void
{
$this->userDetailz->update(
$this->except(['userDetailz', 'email'])

View File

@@ -5,45 +5,44 @@ namespace App\Livewire;
use App\Models\Diary;
use App\Models\Meal;
use App\Models\Portion;
use Illuminate\View\View;
use Livewire\Component;
class MealForm extends Component
{
public $time;
public string $time;
public $type = 0;
public int $type = 0;
public $satiety = 3;
public int $satiety = 3;
public $mood = 3;
public int $mood = 3;
public $product_name;
public string $product_name;
public $portions;
public array $portions;
public $quantity;
public string $quantity;
public $pcs;
public string $pcs;
public $unit;
public string $unit;
public $diaryId;
public int $diaryId;
public Diary $diary;
public Meal $meal;
public $portion;
public string $portion;
protected $rules = [
protected array $rules = [
'product_name' => 'required|min:3',
'quantity' => 'required',
'portion' => 'required|min:1',
];
protected $listeners = ['food-intake-updated' => '$refresh'];
public function mount()
public function mount(): void
{
$this->diary = Diary::find($this->diaryId);
$curMeal = $this->diary->meals->where('type', 0)->first();
@@ -65,7 +64,7 @@ class MealForm extends Component
$this->portions = $curPortions;
}
public function updatingType($value)
public function updatingType(int $value): void
{
$curMeal = $this->diary->meals->where('type', $value)->first();
$this->satiety = $curMeal->satiety ?? 3;
@@ -73,7 +72,7 @@ class MealForm extends Component
$this->time = $curMeal->time ?? now()->setTimezone('3')->format('H:i');
}
public function render()
public function render(): View
{
$types = [0, 1, 2, 3, 4];
$typeNames = ['Завтрак', 'Обед', 'Ужин', 'Ланч', 'Перекусы'];
@@ -99,7 +98,7 @@ class MealForm extends Component
$this->type = $type;
}
public function addFoodIntake(Diary $diary, Meal $meal, Portion $portion)
public function addFoodIntake(Diary $diary, Meal $meal, Portion $portion): void
{
$this->addPortionIfItFilled();
@@ -142,7 +141,7 @@ class MealForm extends Component
$this->dispatch('food-intake-updated')->self();
}
public function addPortion()
public function addPortion(): void
{
$this->validate();
@@ -159,7 +158,7 @@ class MealForm extends Component
$this->reset(['product_name', 'quantity', 'portion']);
}
public function editPortion($key, $item)
public function editPortion(int $key, array $item): void
{
$filed = [
'product_name' => $item['product_name'],
@@ -170,7 +169,7 @@ class MealForm extends Component
$this->fill($filed);
}
public function delPortion($key, $item)
public function delPortion(int $key, array $item): void
{
if (isset($item['id'])) {
Portion::find($item['id'])->delete();
@@ -186,7 +185,12 @@ class MealForm extends Component
$this->portions = array_values($filtered);
}
private function addPortionIfItFilled()
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)) {
$this->addPortion();

View File

@@ -2,11 +2,12 @@
namespace App\Livewire;
use Illuminate\View\View;
use Livewire\Component;
class PortionShow extends Component
{
public function render()
public function render(): View
{
return view('livewire.portion-show');
}

View File

@@ -4,65 +4,69 @@ namespace App\Livewire\ProductNutritional;
use App\Models\ProductGroup;
use App\Models\ProductNutritionalValue;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\UploadedFile;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\Features\SupportRedirects\Redirector;
use Livewire\WithFileUploads;
class Create extends Component
{
use WithFileUploads;
public $name;
public string $name = '';
public $product_group;
public int|string $product_group;
public $image;
public UploadedFile|null $image = null;
public $description;
public string $description = '';
public $formulations;
public string $formulations;
public $energy_on_100gr;
public int $energy_on_100gr;
public $proteins_on_100gr;
public float $proteins_on_100gr;
public $fats_on_100gr;
public float $fats_on_100gr;
public $carbohydrates_on_100gr;
public float $carbohydrates_on_100gr;
public $portion_mass_gr;
public int $portion_mass_gr = 0;
public $energy_on_portion;
public float $energy_on_portion;
public $proteins_on_portion;
public float $proteins_on_portion;
public $fats_on_portion;
public float $fats_on_portion;
public $carbohydrates_on_portion;
public float $carbohydrates_on_portion;
public $curProductNutritionalValue;
public ProductNutritionalValue $curProductNutritionalValue;
public function render()
public function render(): View
{
return view('livewire.product-nutritional.create', ['productGroups' => ProductGroup::all()]);
}
public function save()
public function save(): Redirector|RedirectResponse
{
$productNutritionalVal = ProductNutritionalValue::create([
'name' => $this->name,
'product_group_id' => $this->product_group,
'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;
@@ -70,7 +74,7 @@ class Create extends Component
return redirect()->route('product_nutritional_value.index');
}
public function recalulateVals($mass)
public function recalulateVals(int $mass): void
{
$productKeys = [
['energy_on_100gr', 'energy_on_portion'],
@@ -89,7 +93,7 @@ class Create extends Component
}
}
public function recalulatePortionVals($mass)
public function recalulatePortionVals(int $mass): void
{
$productKeys = [
['energy_on_100gr', 'energy_on_portion'],
@@ -107,21 +111,21 @@ class Create extends Component
}
}
public function updated($name, $value)
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);
}
}
public function delete()
public function delete(): void
{
$this->reset();
$this->curProductNutritionalValue->delete();

View File

@@ -4,44 +4,48 @@ namespace App\Livewire\ProductNutritional;
use App\Models\ProductGroup;
use App\Models\ProductNutritionalValue;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\UploadedFile;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\Features\SupportRedirects\Redirector;
use Livewire\WithFileUploads;
class Edit extends Component
{
use WithFileUploads;
public $name;
public string $name = '';
public $product_group;
public int|string $product_group;
public $image;
public UploadedFile|string $image = '';
public $description;
public string $description = '';
public $formulations;
public string $formulations;
public $energy_on_100gr;
public int $energy_on_100gr;
public $proteins_on_100gr;
public float $proteins_on_100gr;
public $fats_on_100gr;
public float $fats_on_100gr;
public $carbohydrates_on_100gr;
public float $carbohydrates_on_100gr;
public $portion_mass_gr;
public int $portion_mass_gr = 0;
public $energy_on_portion;
public float $energy_on_portion;
public $proteins_on_portion;
public float $proteins_on_portion;
public $fats_on_portion;
public float $fats_on_portion;
public $carbohydrates_on_portion;
public float $carbohydrates_on_portion;
public $product;
public ProductNutritionalValue $product;
public function mount(ProductNutritionalValue $product)
public function mount(ProductNutritionalValue $product): void
{
$this->name = $product->name;
$this->product_group = $product->product_group->id;
@@ -59,15 +63,15 @@ class Edit extends Component
$this->carbohydrates_on_portion = $product->carbohydrates_on_portion;
}
public function render()
public function render(): View
{
return view('livewire.product-nutritional.edit', ['productGroups' => ProductGroup::all()]);
}
public function save()
public function save(): RedirectResponse|Redirector
{
if (! is_string($this->image)) {
$this->product->image = $this->image->store('recipe', 'public');
$this->product->image = $this->image->store('product_nutritional');
}
$this->product->fill([
@@ -75,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();
@@ -91,7 +95,7 @@ class Edit extends Component
return redirect()->route('product_nutritional_value.index');
}
public function recalulateVals($mass)
public function recalulateVals(int $mass): void
{
$productKeys = [
['energy_on_100gr', 'energy_on_portion'],
@@ -110,7 +114,7 @@ class Edit extends Component
}
}
public function recalulatePortionVals($mass)
public function recalulatePortionVals(int $mass): void
{
$productKeys = [
['energy_on_100gr', 'energy_on_portion'],
@@ -128,21 +132,21 @@ class Edit extends Component
}
}
public function updated($name, $value)
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);
}
}
public function delete()
public function delete(): RedirectResponse|Redirector
{
$this->product->delete();

View File

@@ -3,11 +3,12 @@
namespace App\Livewire\ProductNutritional;
use App\Models\ProductNutritionalValue;
use Illuminate\View\View;
use Livewire\Component;
class Index extends Component
{
public function render()
public function render(): View
{
return view('livewire.product-nutritional.index', ['products' => ProductNutritionalValue::all()]);
}

View File

@@ -4,21 +4,22 @@ namespace App\Livewire\Profile;
use App\Models\User;
use Asantibanez\LivewireCharts\Models\LineChartModel;
use Illuminate\View\View;
use Livewire\Component;
class CircumferenceChart extends Component
{
public User $user;
protected $listeners = ['circumference-chart-updated' => '$refresh'];
public function render()
public function render(): View
{
$lastOneMisure = $this
->user
->circumference_measures()
->get()
->last();
->latest()
->first();
// ->get()
// ->last();
$lastFourMisures = $this
->user
@@ -52,4 +53,9 @@ class CircumferenceChart extends Component
]
);
}
protected function getListeners(): array
{
return ['circumference-chart-updated' => '$refresh'];
}
}

View File

@@ -2,22 +2,24 @@
namespace App\Livewire\Profile;
use App\Models\User;
use App\Models\UserDetailz;
use Illuminate\View\View;
use Livewire\Component;
class DescriptionForm extends Component
{
public $description = '';
public string $description = '';
public $user;
public User $user;
public function mount()
public function mount(): void
{
$this->initDetailzIfNeeded();
$this->description = $this->user->detailz->additional_info ?? '';
}
public function updatedDescription($value)
public function updatedDescription(string $value): void
{
$userDetailz = $this->user->detailz;
@@ -25,12 +27,12 @@ class DescriptionForm extends Component
$userDetailz->save();
}
public function render()
public function render(): View
{
return view('livewire.profile.description-form');
}
private function initDetailzIfNeeded()
private function initDetailzIfNeeded(): void
{
$curUserDetailez = UserDetailz::firstOrNew(
['user_id' => $this->user->id],
@@ -44,8 +46,12 @@ class DescriptionForm extends Component
]
);
if (is_null($curUserDetailez->id)) {
if (! isset($curUserDetailez->id)) {
$curUserDetailez->save();
}
// if (is_null($curUserDetailez->id)) {
// $curUserDetailez->save();
// }
}
}

View File

@@ -7,6 +7,7 @@ use App\Models\User;
use App\Models\UserDetailz;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\View\View;
use Livewire\Component;
class EditDetailzForm extends Component
@@ -17,21 +18,21 @@ class EditDetailzForm extends Component
public string $currentPassword;
public string $newPassword;
public string $newPassword = '';
public string $newPasswordConfirm;
public string $newPasswordConfirm = '';
public array $validatedData = [];
public ProfileEditDetailzForm $detailzForm;
public function mount(User $user)
public function mount(User $user): void
{
$this->detailz = $user->detailz;
$this->detailzForm->setDetailz($user->detailz);
}
public function updatePassword()
public function updatePassword(): void
{
$validatedData = Validator::make(
['currentPassword' => $this->currentPassword, 'newPassword' => $this->newPassword, 'newPasswordConfirm' => $this->newPasswordConfirm],
@@ -54,12 +55,12 @@ class EditDetailzForm extends Component
/* dd($this->currentPassword, $this->newPassword, $this->newPasswordConfirm, $validatedData); */
}
public function refineDetailz()
public function refineDetailz(): void
{
$this->detailzForm->update();
}
public function render()
public function render(): View
{
return view('livewire.profile.edit-detailz-form');
}

View File

@@ -2,40 +2,29 @@
namespace App\Livewire\Profile;
use App\Models\User;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
use Livewire\Component;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use Livewire\WithFileUploads;
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 $isOnline = false;
public bool|int $isOnline = false;
public $user;
public User $user;
/**
* Prepare the component.
*
* @return void
*/
public function mount()
public function mount(): void
{
$this->state = $this->user->withoutRelations()->toArray();
@@ -51,12 +40,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();
@@ -70,36 +54,26 @@ class PhotoForm extends Component
$this->dispatch('saved');
}
public function updatedPhoto($newPhoto)
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;
}
public function render()
public function render(): View
{
return view('livewire.profile.photo-form');
}

View File

@@ -2,43 +2,48 @@
namespace App\Livewire\Profile;
use App\Models\User;
use App\Models\UserDetailz;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\Features\SupportRedirects\Redirector;
use Masmerise\Toaster\Toaster;
class ShowDetailz extends Component
{
public $user;
public User $user;
public $userDetailzAttributes;
public array $userDetailzAttributes;
public $regFormKeys;
public array $regFormKeys;
public $userDetailz;
public UserDetailz $userDetailz;
public $publicity;
public bool|int $publicity;
public $is_bedtime_fillable;
public bool|int $is_bedtime_fillable;
public $is_mood_fillable;
public bool|int $is_mood_fillable;
public function mount()
public function mount(): void
{
$this->is_mood_fillable = $this->user->detailz->is_mood_fillable;
$this->is_bedtime_fillable = $this->user->detailz->is_bedtime_fillable;
$this->publicity = $this->user->is_public_profile;
}
public function render()
public function render(): View
{
return view('livewire.profile.show-detailz');
}
public function editAction()
public function editAction(): Redirector|RedirectResponse
{
return redirect()->route('user_detailz.edit', $this->userDetailz->id);
}
public function updated($name, $value): void
public function updated(string $name, bool $value): void
{
if ($name === 'is_bedtime_fillable') {
$this->user->detailz->update(['is_bedtime_fillable' => $value]);

View File

@@ -4,15 +4,14 @@ namespace App\Livewire\Profile;
use App\Models\User;
use Asantibanez\LivewireCharts\Models\AreaChartModel;
use Illuminate\View\View;
use Livewire\Component;
class WeightChart extends Component
{
public User $user;
protected $listeners = ['weight-chart-updated' => '$refresh'];
public function render()
public function render(): View
{
$areaChartModel =
(new AreaChartModel())
@@ -41,4 +40,9 @@ class WeightChart extends Component
]
);
}
protected function getListeners(): array
{
return ['weight-chart-updated' => '$refresh'];
}
}

View File

@@ -5,87 +5,84 @@ namespace App\Livewire\Registration;
use App\Actions\Fortify\CreateNewUser;
use App\Rules\MinWords;
use Illuminate\Auth\Events\Registered;
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\View\View;
use Livewire\Component;
// use \Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use Livewire\Features\SupportRedirects\Redirector;
class Step1 extends Component
{
public $step;
public string $step;
public $first_name;
public string $first_name = '';
public $last_name;
public string $last_name = '';
public $email;
public string $email = '';
public $password;
public string $password = '';
public $password_confirmation;
public string $password_confirmation = '';
public $birthdate;
public string $birthdate;
public $gender = 'male';
public string $gender = 'male';
public $country = 'ru';
public string $country = 'ru';
public $city = 'msk';
public string $city = 'msk';
public $lang = 'ru';
public string $lang = 'ru';
public $weight;
public string $weight = '';
public $height;
public string $height = '';
public $chest_circumference;
public string $chest_circumference = '';
public $waist_circumference;
public string $waist_circumference = '';
public $hip_circumference;
public string $hip_circumference = '';
public $blood_pressure_up;
public string $blood_pressure_up = '';
public $blood_pressure_down;
public string $blood_pressure_down = '';
public $has_hypo = 0;
public int|string $has_hypo = 0;
public $has_hyper = 0;
public int|string $has_hyper = 0;
public $about_alergy;
public string $about_alergy = '';
public $about_taking_pils;
public string $about_taking_pils = '';
public $about_sport_hobbies;
public string $about_sport_hobbies = '';
public $favorite_foods;
public string $favorite_foods = '';
public $unfavorite_foods;
public string $unfavorite_foods = '';
public $additional_info;
public string $additional_info = '';
public function mount($step)
public function mount(string $step): void
{
$this->step = $step;
collect(session()->get('registrationdata', []))
->each(fn ($item, $key) => $this->{$key} = $item);
}
public function render()
public function render(): View
{
return view('livewire.registration.'.$this->step, ['step' => $this->step])
return view('livewire.registration.' . $this->step, ['step' => $this->step])
->extends('layouts.register');
}
public function nextStep()
public function nextStep(): RedirectResponse|Redirector
{
$validatedData = Validator::make(
$this->getValidateData($this->step),
@@ -106,7 +103,7 @@ class Step1 extends Component
);
}
public function skipStep()
public function skipStep(): RedirectResponse|Redirector
{
$validatedData = $this->getValidateData($this->step);
$registrationdata = session()->get('registrationdata', []);
@@ -123,9 +120,9 @@ class Step1 extends Component
);
}
public function goBack()
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(
@@ -136,7 +133,7 @@ class Step1 extends Component
);
}
public function finishRegistretion()
public function finishRegistretion(): RedirectResponse|Redirector
{
$validatedData = Validator::make(
$this->getValidateData($this->step),
@@ -157,7 +154,7 @@ class Step1 extends Component
return redirect()->route('profile.show', $user->id);
}
private function getValidateRules($key)
private function getValidateRules(string $key): array
{
$rules = [
'step1' => [
@@ -199,7 +196,7 @@ class Step1 extends Component
return $rules[$key];
}
private function getValidateData($key)
private function getValidateData(string $key): array
{
$data = [
'step1' => [
@@ -242,8 +239,8 @@ class Step1 extends Component
return $data[$key];
}
private function getNextStep()
private function getNextStep(): string
{
return 'step'.(int) Str::replaceFirst('step', '', $this->step) + 1;
return 'step' . ((int) Str::replaceFirst('step', '', $this->step) + 1);
}
}

View File

@@ -3,22 +3,26 @@
namespace App\Livewire;
// use App\Models\BlogPost;
use App\Models\BlogPost;
use App\Models\Recipe;
use App\Models\Tag;
use Illuminate\View\View;
use Livewire\Attributes\On;
use Livewire\Component;
class TagsComponent extends Component
{
public $tags;
public string $tags;
public $parentComponent;
public Recipe|BlogPost $parentComponent;
// protected $listeners = ['tagAdded', 'tagRemoved'];
public function mount($parentComponent = null)
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);
}
@@ -44,7 +48,7 @@ class TagsComponent extends Component
$this->dispatch('parentComponentTagRemoved', tag: $tag);
}
public function render()
public function render(): View
{
return view('livewire.tags-component');
}

View File

@@ -7,29 +7,30 @@ namespace App\Livewire\User;
use App\Models\CircumferenceMeasure;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use LivewireUI\Modal\ModalComponent;
class AddCircumference extends ModalComponent
{
public User $user;
public $chest_circumference = 0;
public int $chest_circumference = 0;
public $waist_circumference = 0;
public int $waist_circumference = 0;
public $hip_circumference = 0;
public int $hip_circumference = 0;
public function mount()
public function mount(): void
{
$this->user = Auth::user();
}
public function render()
public function render(): View
{
return view('livewire.user.add-circumference');
}
public function add()
public function add(): void
{
$newMeasure = CircumferenceMeasure::create([
'user_id' => $this->user->id,

View File

@@ -5,25 +5,26 @@ namespace App\Livewire\User;
use App\Models\User;
use App\Models\WeightMeasure;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use LivewireUI\Modal\ModalComponent;
class AddWeight extends ModalComponent
{
public User $user;
public $weight = 0;
public int $weight = 0;
public function mount()
public function mount(): void
{
$this->user = Auth::user();
}
public function render()
public function render(): View
{
return view('livewire.user.add-weight');
}
public function add()
public function add(): void
{
$newMeasure = WeightMeasure::create([
'user_id' => $this->user->id,

View File

@@ -121,7 +121,7 @@ class BlogPost extends Model implements Viewable
return $query->setEagerLoads([]);
}
public function scopeContainsTag(Builder $query, string $tagString): Builder
public function scopeContainsTag(Builder $query, string $tagString): MorphToMany
{
$tagId = Str::of($tagString)->split('/-/')->first();

View File

@@ -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

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -36,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)
public function scopeWithLastUserMessage(Builder $query, int $userId): Model|null
{
return $query
->where('from_user_id', $userId)
@@ -45,7 +46,7 @@ class Chat extends Model
->first();
}
public function scopeWithLastTenMessages(mixed $query, int $userId, int $recipientId)
public function scopeWithLastTenMessages(Builder $query, int $userId, int $recipientId): Builder
{
return $query
->where('from_user_id', $userId)
@@ -58,7 +59,7 @@ class Chat extends Model
->limit(20);
}
public function scopeWithLastMessage(mixed $query, int $userId, int $recipientId)
public function scopeWithLastMessage(Builder $query, int $userId, int $recipientId): Model|null
{
return $query
->where('from_user_id', $userId)

View File

@@ -5,6 +5,7 @@ namespace App\Models;
use Iben\Statable\Statable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* App\Models\ChosenDiet
@@ -46,27 +47,27 @@ class ChosenDiet extends Model
'start_date',
];
public function getActorId()
public function getActorId(): int
{
return $this->user_id;
}
public function user()
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function diet()
public function diet(): BelongsTo
{
return $this->belongsTo(Diet::class);
}
protected function getGraph()
protected function getGraph(): string
{
return 'chosen_diet';
}
protected function saveBeforeTransition()
protected function saveBeforeTransition(): bool
{
return true;
}

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* App\Models\CircumferenceMeasure
@@ -37,7 +38,7 @@ class CircumferenceMeasure extends Model
protected $guarded = [];
public function user()
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* App\Models\ConsultantEducation
@@ -45,7 +46,7 @@ class ConsultantEducation extends Model
protected $guarded = [];
public function user()
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

View File

@@ -2,9 +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;
/**
* App\Models\Diary
@@ -16,7 +19,7 @@ use Illuminate\Database\Eloquent\Model;
* @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
@@ -49,26 +52,26 @@ class Diary extends Model
// protected $casts = ['date' => 'datetime:d-m-Y'];
// protected $dateFormat = 'd-m-Y';
public function user()
public function user(): BelongsTo
{
return $this->belongsTo(User::class)->withDefault([
'name' => 'Guest Author',
]);
}
public function meals()
public function meals(): HasMany
{
return $this->hasMany(Meal::class);
}
public function scopeUserToDayItem($query, $userId)
public function scopeUserToDayItem(Builder $query, int $userId): Builder
{
return $query
->where('user_id', $userId)
->where('date', now()->format('Y-m-d'));
}
public function consultant_comments()
public function consultant_comments(): HasMany
{
return $this->hasMany(ConsultantDiaryComment::class);
}

View File

@@ -8,6 +8,7 @@ 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\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
@@ -64,20 +65,30 @@ class Diet extends Model implements Viewable
{
use HasFactory, InteractsWithViews;
protected $withCount = [
'likes',
'comments',
'choses',
protected $casts = [
'type' => 'array',
'daily_schedule' => 'array',
];
private $allowedDietTypes = [
private array $allowedDietTypes = [
'alko',
'corb',
'meat',
'veg',
];
public function author()
// protected $withCount = [
// 'likes',
// 'comments',
// 'choses',
// ];
public static function getWithLikesCommentsChosesCount(): Builder
{
return self::withCount(['likes', 'comments', 'choses']);
}
public function author(): BelongsToMany
{
return $this
->belongsToMany(User::class, 'diet_author', 'diet_id', 'user_id');
@@ -90,7 +101,7 @@ class Diet extends Model implements Viewable
);*/
}
public function comments()
public function comments(): HasMany
{
return $this->hasMany(DietComment::class);
}
@@ -100,7 +111,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();
@@ -109,7 +120,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();
@@ -120,7 +131,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),
@@ -129,60 +140,51 @@ 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,
);
}
public function choses()
public function choses(): HasMany
{
return $this->hasMany(ChosenDiet::class);
}
public function scopeDurationMin(Builder $query, $days): Builder
public function scopeDurationMin(Builder $query, string $days): Builder
{
return $query->where('duration', '>=', $days);
}
public function scopeDurationMax(Builder $query, $days): Builder
public function scopeDurationMax(Builder $query, string $days): Builder
{
return $query->where('duration', '<=', $days);
}
public function scopeInvolvedMin(Builder $query, $number): Builder
public function scopeInvolvedMin(Builder $query, string $number): Builder
{
return $query->having('choses_count', '>=', $number);
}
public function scopeInvolvedMax(Builder $query, $number): Builder
public function scopeInvolvedMax(Builder $query, string $number): Builder
{
return $query->having('choses_count', '<=', $number);
}
public function scopeContainsType(Builder $query, $types): Builder
public function scopeContainsType(Builder $query, array $types): Builder
{
$i = 0;
foreach ($types as $type) {
if (in_array($type, $this->allowedDietTypes)) {
$query = $i === 0
? $query->whereJsonContainsKey('type->'.$type)
: $query->orWhereJsonContainsKey('type->'.$type);
? $query->whereJsonContainsKey('type->' . $type)
: $query->orWhereJsonContainsKey('type->' . $type);
$i++;
}
}
return $query;
}
private function unserializeOptionsArr($str)
{
if (preg_match('/^".*"$/', $str)) {
return json_decode(stripslashes(mb_substr($str, 1, -1)), true);
}
return json_decode(stripslashes($str), true);
}
}

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
@@ -39,12 +40,12 @@ class DietComment extends Model
{
use HasFactory;
public function author()
public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
public function diet()
public function diet(): BelongsTo
{
return $this->belongsTo(Diet::class, 'diet_id');
}
@@ -54,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()
@@ -67,7 +68,7 @@ class DietComment extends Model
return false;
}
public function isDownVoted(): bool
public function isDownVoted(): bool|int
{
if (auth()->user()) {
return auth()
@@ -80,7 +81,7 @@ class DietComment extends Model
return false;
}
public function removeUpVote(): bool
public function removeUpVote(): bool|int
{
if (auth()->user()) {
return auth()

View File

@@ -2,8 +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;
/**
* App\Models\DietCommentUpvote
@@ -42,22 +44,22 @@ class DietCommentUpvote extends Model
'type',
];
public function author()
public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
public function diet_comment()
public function diet_comment(): BelongsTo
{
return $this->belongsTo(DietComment::class, 'comment_id');
}
public function scopeForDietCommentsUpVote($query, DietComment $comment)
public function scopeForDietCommentsUpVote(Builder $query, DietComment $comment): Builder
{
return $query->where('comment_id', $comment->id)->where('type', 'upvote');
}
public function scopeForDietCommentsDownVote($query, DietComment $comment)
public function scopeForDietCommentsDownVote(Builder $query, DietComment $comment): Builder
{
return $query->where('comment_id', $comment->id)->where('type', 'downvote');
}

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -34,7 +35,7 @@ class DietLike extends Model
'user_id',
];
public function scopeForDiet($query, Diet $diet)
public function scopeForDiet(Builder $query, Diet $diet): Builder
{
return $query->where('diet_id', $diet->id);
}

View File

@@ -4,6 +4,9 @@ namespace App\Models;
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\Eloquent\Relations\HasMany;
/**
* App\Models\Meal
@@ -46,24 +49,24 @@ class Meal extends Model
protected $fillable = ['*'];
public function user()
public function user(): BelongsTo
{
return $this->belongsTo(User::class)->withDefault([
'name' => 'Guest Author',
]);
}
public function diary()
public function diary(): BelongsTo
{
return $this->belongsTo(Diary::class);
}
public function portions()
public function portions(): HasMany
{
return $this->hasMany(Portion::class);
}
public function photos()
public function photos(): BelongsToMany
{
return $this->belongsToMany(UserAttachment::class);
}

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* App\Models\Portion
@@ -37,7 +38,7 @@ class Portion extends Model
protected $fillable = ['*'];
public function user()
public function user(): BelongsTo
{
return $this->belongsTo(Meal::class);
}

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* App\Models\ProductGroup
@@ -34,7 +35,7 @@ class ProductGroup extends Model
protected $fillable = ['name'];
public function product_nutritional_value()
public function product_nutritional_value(): HasMany
{
return $this->hasMany(ProductNutritionalValue::class);
}

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* App\Models\ProductNutritionalValue
@@ -57,7 +58,7 @@ class ProductNutritionalValue extends Model
protected $guarded = [];
public function product_group()
public function product_group(): BelongsTo
{
return $this->belongsTo(ProductGroup::class);
}

View File

@@ -38,7 +38,7 @@ class Tag extends Model
protected $guarded = [];
public function blogPosts()
public function blogPosts(): MorphToMany
{
return $this->morphedByMany(BlogPost::class, 'taggable', 'taggables');
}

View File

@@ -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

View File

@@ -2,8 +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;
/**
* App\Models\UserAttachment
@@ -44,17 +47,17 @@ class UserAttachment extends Model
protected $guarded = [];
public function user()
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function scopeCerts($query)
public function scopeCerts(Builder $query): Builder
{
return $query->where('user_attachments.group', 'user_certs');
}
public function meals()
public function meals(): BelongsToMany
{
return $this->belongsToMany(Meal::class);
}

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* App\Models\UserDetailz
@@ -80,7 +81,7 @@ class UserDetailz extends Model
protected $guarded = [];
public function user()
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* App\Models\WeightMeasure
@@ -33,7 +34,7 @@ class WeightMeasure extends Model
protected $guarded = [];
public function user()
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

View File

@@ -12,7 +12,7 @@ class ConsultantRequestStarted extends Notification implements ShouldQueue
{
use Queueable;
private ConsultantEducation $education;
public ConsultantEducation $education;
/**
* Create a new notification instance.

View File

@@ -11,39 +11,23 @@ class DietStarted extends Notification implements ShouldQueue
{
use Queueable;
public $chosenDiet;
public object $chosenDiet;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($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)
@@ -51,14 +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 [

View File

@@ -6,21 +6,21 @@ use Illuminate\Contracts\Validation\Rule;
class MinWords implements Rule
{
protected $minWords;
protected int $minWords;
public function __construct($minWords)
public function __construct(int $minWords)
{
$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));
return $wordCount >= $this->minWords;
}
public function message()
public function message(): string
{
return "The :attribute must have at least {$this->minWords} words.";
}

View File

@@ -6,65 +6,74 @@ use App\Models\BlogPost;
use App\Models\Recipe;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
class FeedService
{
public static function showActualFeed()
public static function showActualFeed(): Collection
{
$dateMax = Recipe::max('created_at');
$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);
}
}

View File

@@ -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,
/*
|--------------------------------------------------------------------------

View File

@@ -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',

View File

@@ -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;

View File

@@ -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,

View 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)),
];
}
}

View 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;
}
}

View File

@@ -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(),
];

View File

@@ -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>

View File

@@ -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');
}

View File

@@ -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);
}
}

View 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();
}
);
}
}

View File

@@ -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());

View File

@@ -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());

View File

@@ -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());

View File

@@ -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),

View File

@@ -0,0 +1,187 @@
<?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());
}
}

View 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);
}
}

View 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();
}
}

View 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();
}
}

View File

@@ -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();

View File

@@ -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');

View File

@@ -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();

View File

@@ -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);

View File

@@ -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);

View 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());
// }
// }

View 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);
}
}

View 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();
}
}

View 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);
// }
}

View File

@@ -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

View File

@@ -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', [

View File

@@ -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());

View File

@@ -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);