diff --git a/.env.example b/.env.example index 58f4843..d86ff73 100644 --- a/.env.example +++ b/.env.example @@ -19,7 +19,7 @@ DB_PASSWORD="eatvio_pass_nhbnhb22" BROADCAST_DRIVER=log CACHE_DRIVER=file -FILESYSTEM_DISK=local +FILESYSTEM_DISK=public QUEUE_CONNECTION=sync SESSION_DRIVER=database SESSION_LIFETIME=120 diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index 80105f8..c81677d 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -1,4 +1,4 @@ -name: 'Test new actor runner 1.1.2' +name: "Test new actor runner 1.1.2.1" on: pull_request: branches: @@ -10,8 +10,8 @@ jobs: name: Test env: extensions: sqlite3, gd - php-version: '8.2' - key: cache-v1.1.1 # can be any string, change to clear the extension cache. + php-version: "8.2" + key: "cache-v1.1.2.1" # can be any string, change to clear the extension cache. steps: - uses: actions/checkout@v3 @@ -65,13 +65,10 @@ jobs: - name: Code Rewiew run: vendor/bin/rector process --dry-run #- name: Run Pint - # run: vendor/bin/pint + # run: vendor/bin/pint - name: Run PHP Insides - run: vendor/bin/phpinsights --no-interaction --min-quality=80 --min-complexity=90 --min-architecture=75 --min-style=95 + run: vendor/bin/phpinsights --config-path=./config/insights.php --no-interaction --min-quality=80 --min-complexity=90 --min-architecture=75 --min-style=95 - name: Run Static Analysis run: composer static-analysis - - - diff --git a/_ide_helper.php b/_ide_helper.php index 40375eb..f90a270 100644 --- a/_ide_helper.php +++ b/_ide_helper.php @@ -4,7 +4,7 @@ /** * A helper file for Laravel, to provide autocomplete information to your IDE - * Generated for Laravel 10.37.3. + * Generated for Laravel 10.38.0. * * This file should not be included in your code, only analyzed by your IDE! * @@ -19159,550 +19159,12 @@ } -} - - namespace Jenssegers\Agent\Facades { - /** - * - * - */ - class Agent { - /** - * Get all detection rules. These rules include the additional - * platforms and browsers and utilities. - * - * @return array - * @static - */ - public static function getDetectionRulesExtended() - { - return \Jenssegers\Agent\Agent::getDetectionRulesExtended(); - } - /** - * - * - * @static - */ - public static function getRules() - { - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->getRules(); - } - /** - * - * - * @return \Jaybizzle\CrawlerDetect\CrawlerDetect - * @static - */ - public static function getCrawlerDetect() - { - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->getCrawlerDetect(); - } - /** - * - * - * @static - */ - public static function getBrowsers() - { - return \Jenssegers\Agent\Agent::getBrowsers(); - } - /** - * - * - * @static - */ - public static function getOperatingSystems() - { - return \Jenssegers\Agent\Agent::getOperatingSystems(); - } - /** - * - * - * @static - */ - public static function getPlatforms() - { - return \Jenssegers\Agent\Agent::getPlatforms(); - } - /** - * - * - * @static - */ - public static function getDesktopDevices() - { - return \Jenssegers\Agent\Agent::getDesktopDevices(); - } - /** - * - * - * @static - */ - public static function getProperties() - { - return \Jenssegers\Agent\Agent::getProperties(); - } - /** - * Get accept languages. - * - * @param string $acceptLanguage - * @return array - * @static - */ - public static function languages($acceptLanguage = null) - { - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->languages($acceptLanguage); - } - /** - * Get the browser name. - * - * @param string|null $userAgent - * @return string|bool - * @static - */ - public static function browser($userAgent = null) - { - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->browser($userAgent); - } - /** - * Get the platform name. - * - * @param string|null $userAgent - * @return string|bool - * @static - */ - public static function platform($userAgent = null) - { - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->platform($userAgent); - } - /** - * Get the device name. - * - * @param string|null $userAgent - * @return string|bool - * @static - */ - public static function device($userAgent = null) - { - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->device($userAgent); - } - /** - * Check if the device is a desktop computer. - * - * @param string|null $userAgent deprecated - * @param array $httpHeaders deprecated - * @return bool - * @static - */ - public static function isDesktop($userAgent = null, $httpHeaders = null) - { - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->isDesktop($userAgent, $httpHeaders); - } - /** - * Check if the device is a mobile phone. - * - * @param string|null $userAgent deprecated - * @param array $httpHeaders deprecated - * @return bool - * @static - */ - public static function isPhone($userAgent = null, $httpHeaders = null) - { - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->isPhone($userAgent, $httpHeaders); - } - /** - * Get the robot name. - * - * @param string|null $userAgent - * @return string|bool - * @static - */ - public static function robot($userAgent = null) - { - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->robot($userAgent); - } - /** - * Check if device is a robot. - * - * @param string|null $userAgent - * @return bool - * @static - */ - public static function isRobot($userAgent = null) - { - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->isRobot($userAgent); - } - /** - * Get the device type - * - * @param null $userAgent - * @param null $httpHeaders - * @return string - * @static - */ - public static function deviceType($userAgent = null, $httpHeaders = null) - { - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->deviceType($userAgent, $httpHeaders); - } - /** - * - * - * @static - */ - public static function version($propertyName, $type = 'text') - { - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->version($propertyName, $type); - } - /** - * Get the current script version. - * - * This is useful for the demo.php file, - * so people can check on what version they are testing - * for mobile devices. - * - * @return string The version number in semantic version format. - * @static - */ - public static function getScriptVersion() - { //Method inherited from \Mobile_Detect - return \Jenssegers\Agent\Agent::getScriptVersion(); - } - /** - * Set the HTTP Headers. Must be PHP-flavored. This method will reset existing headers. - * - * @param array $httpHeaders The headers to set. If null, then using PHP's _SERVER to extract - * the headers. The default null is left for backwards compatibility. - * @static - */ - public static function setHttpHeaders($httpHeaders = null) - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->setHttpHeaders($httpHeaders); - } - /** - * Retrieves the HTTP headers. - * - * @return array - * @static - */ - public static function getHttpHeaders() - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->getHttpHeaders(); - } - /** - * Retrieves a particular header. If it doesn't exist, no exception/error is caused. - * - * Simply null is returned. - * - * @param string $header The name of the header to retrieve. Can be HTTP compliant such as - * "User-Agent" or "X-Device-User-Agent" or can be php-esque with the - * all-caps, HTTP_ prefixed, underscore separated awesomeness. - * @return string|null The value of the header. - * @static - */ - public static function getHttpHeader($header) - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->getHttpHeader($header); - } - /** - * - * - * @static - */ - public static function getMobileHeaders() - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->getMobileHeaders(); - } - /** - * Get all possible HTTP headers that - * can contain the User-Agent string. - * - * @return array List of HTTP headers. - * @static - */ - public static function getUaHttpHeaders() - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->getUaHttpHeaders(); - } - /** - * Set CloudFront headers - * http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html#header-caching-web-device - * - * @param array $cfHeaders List of HTTP headers - * @return boolean If there were CloudFront headers to be set - * @static - */ - public static function setCfHeaders($cfHeaders = null) - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->setCfHeaders($cfHeaders); - } - /** - * Retrieves the cloudfront headers. - * - * @return array - * @static - */ - public static function getCfHeaders() - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->getCfHeaders(); - } - /** - * Set the User-Agent to be used. - * - * @param string $userAgent The user agent string to set. - * @return string|null - * @static - */ - public static function setUserAgent($userAgent = null) - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->setUserAgent($userAgent); - } - /** - * Retrieve the User-Agent. - * - * @return string|null The user agent if it's set. - * @static - */ - public static function getUserAgent() - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->getUserAgent(); - } - /** - * Set the detection type. Must be one of self::DETECTION_TYPE_MOBILE or - * self::DETECTION_TYPE_EXTENDED. Otherwise, nothing is set. - * - * @deprecated since version 2.6.9 - * @param string $type The type. Must be a self::DETECTION_TYPE_* constant. The default - * parameter is null which will default to self::DETECTION_TYPE_MOBILE. - * @static - */ - public static function setDetectionType($type = null) - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->setDetectionType($type); - } - /** - * - * - * @static - */ - public static function getMatchingRegex() - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->getMatchingRegex(); - } - /** - * - * - * @static - */ - public static function getMatchesArray() - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->getMatchesArray(); - } - /** - * Retrieve the list of known phone devices. - * - * @return array List of phone devices. - * @static - */ - public static function getPhoneDevices() - { //Method inherited from \Mobile_Detect - return \Jenssegers\Agent\Agent::getPhoneDevices(); - } - /** - * Retrieve the list of known tablet devices. - * - * @return array List of tablet devices. - * @static - */ - public static function getTabletDevices() - { //Method inherited from \Mobile_Detect - return \Jenssegers\Agent\Agent::getTabletDevices(); - } - /** - * Alias for getBrowsers() method. - * - * @return array List of user agents. - * @static - */ - public static function getUserAgents() - { //Method inherited from \Mobile_Detect - return \Jenssegers\Agent\Agent::getUserAgents(); - } - /** - * Retrieve the list of known utilities. - * - * @return array List of utilities. - * @static - */ - public static function getUtilities() - { //Method inherited from \Mobile_Detect - return \Jenssegers\Agent\Agent::getUtilities(); - } - /** - * Method gets the mobile detection rules. This method is used for the magic methods $detect->is*(). - * - * @deprecated since version 2.6.9 - * @return array All the rules (but not extended). - * @static - */ - public static function getMobileDetectionRules() - { //Method inherited from \Mobile_Detect - return \Jenssegers\Agent\Agent::getMobileDetectionRules(); - } - /** - * Method gets the mobile detection rules + utilities. - * - * The reason this is separate is because utilities rules - * don't necessary imply mobile. This method is used inside - * the new $detect->is('stuff') method. - * - * @deprecated since version 2.6.9 - * @return array All the rules + extended. - * @static - */ - public static function getMobileDetectionRulesExtended() - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->getMobileDetectionRulesExtended(); - } - /** - * Check the HTTP headers for signs of mobile. - * - * This is the fastest mobile check possible; it's used - * inside isMobile() method. - * - * @return bool - * @static - */ - public static function checkHttpHeadersForMobile() - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->checkHttpHeadersForMobile(); - } - /** - * Check if the device is mobile. - * - * Returns true if any type of mobile device detected, including special ones - * - * @param null $userAgent deprecated - * @param null $httpHeaders deprecated - * @return bool - * @static - */ - public static function isMobile($userAgent = null, $httpHeaders = null) - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->isMobile($userAgent, $httpHeaders); - } - /** - * Check if the device is a tablet. - * - * Return true if any type of tablet device is detected. - * - * @param string $userAgent deprecated - * @param array $httpHeaders deprecated - * @return bool - * @static - */ - public static function isTablet($userAgent = null, $httpHeaders = null) - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->isTablet($userAgent, $httpHeaders); - } - /** - * This method checks for a certain property in the - * userAgent. - * - * @todo : The httpHeaders part is not yet used. - * @param string $key - * @param string $userAgent deprecated - * @param string $httpHeaders deprecated - * @return bool|int|null - * @static - */ - public static function is($key, $userAgent = null, $httpHeaders = null) - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->is($key, $userAgent, $httpHeaders); - } - /** - * Some detection rules are relative (not standard), - * because of the diversity of devices, vendors and - * their conventions in representing the User-Agent or - * the HTTP headers. - * - * This method will be used to check custom regexes against - * the User-Agent string. - * - * @param $regex - * @param string $userAgent - * @return bool - * @todo : search in the HTTP headers too. - * @static - */ - public static function match($regex, $userAgent = null) - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->match($regex, $userAgent); - } - /** - * Prepare the version number. - * - * @todo Remove the error supression from str_replace() call. - * @param string $ver The string version, like "2.6.21.2152"; - * @return float - * @static - */ - public static function prepareVersionNo($ver) - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->prepareVersionNo($ver); - } - /** - * Retrieve the mobile grading, using self::MOBILE_GRADE_* constants. - * - * @deprecated This is no longer being maintained, it was an experiment at the time. - * @return string One of the self::MOBILE_GRADE_* constants. - * @static - */ - public static function mobileGrade() - { //Method inherited from \Mobile_Detect - /** @var \Jenssegers\Agent\Agent $instance */ - return $instance->mobileGrade(); - } - - } - } namespace Livewire { /** * * - * @method static void setUpdateUri() * @see \Livewire\LivewireManager */ class Livewire { @@ -19971,6 +19433,36 @@ * * @static */ + public static function withCookie($name, $value) + { + /** @var \Livewire\LivewireManager $instance */ + return $instance->withCookie($name, $value); + } + /** + * + * + * @static + */ + public static function withCookies($cookies) + { + /** @var \Livewire\LivewireManager $instance */ + return $instance->withCookies($cookies); + } + /** + * + * + * @static + */ + public static function withHeaders($headers) + { + /** @var \Livewire\LivewireManager $instance */ + return $instance->withHeaders($headers); + } + /** + * + * + * @static + */ public static function test($name, $params = []) { /** @var \Livewire\LivewireManager $instance */ @@ -20714,13 +20206,9 @@ return $instance->captureLastError($hint); } /** - * + * {@inheritdoc} * - * @param string $slug Identifier of the Monitor - * @param \Sentry\CheckInStatus $status The status of the check-in - * @param int|float|null $duration The duration of the check-in - * @param \Sentry\MonitorConfig|null $monitorConfig Configuration of the Monitor - * @param string|null $checkInId A check-in ID from the previous check-in + * @param int|float|null $duration * @static */ public static function captureCheckIn($slug, $status, $duration = null, $monitorConfig = null, $checkInId = null) @@ -21540,6 +21028,17 @@ public static function layout($view, $params = []) { return \Illuminate\View\View::layout($view, $params); + } + /** + * + * + * @see \Livewire\Features\SupportPageComponents\SupportPageComponents::registerLayoutViewMacros() + * @param callable $callback + * @static + */ + public static function response($callback) + { + return \Illuminate\View\View::response($callback); } } @@ -21555,7 +21054,7 @@ /** * * - * @see \Sentry\Laravel\Features\ConsoleIntegration::setupInactive() + * @see \Sentry\Laravel\Features\ConsoleIntegration::onBootInactive() * @param string|null $monitorSlug * @param int|null $checkInMargin * @param int|null $maxRuntime @@ -25532,7 +25031,6 @@ namespace { class View extends \Illuminate\Support\Facades\View {} class Vite extends \Illuminate\Support\Facades\Vite {} class Debugbar extends \Barryvdh\Debugbar\Facades\Debugbar {} - class Agent extends \Jenssegers\Agent\Facades\Agent {} class Livewire extends \Livewire\Livewire {} class Toaster extends \Masmerise\Toaster\Toaster {} class LaravelLocalization extends \Mcamara\LaravelLocalization\Facades\LaravelLocalization {} diff --git a/app/Actions/Fortify/UpdateUserProfileInformation.php b/app/Actions/Fortify/UpdateUserProfileInformation.php index 47e8e62..cd0795a 100644 --- a/app/Actions/Fortify/UpdateUserProfileInformation.php +++ b/app/Actions/Fortify/UpdateUserProfileInformation.php @@ -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 $input + * @param array $input */ public function update(User $user, array $input): void { @@ -23,9 +24,9 @@ class UpdateUserProfileInformation implements UpdatesUserProfileInformation 'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'], ])->validateWithBag('updateProfileInformation'); - if (isset($input['photo'])) { + /*if (isset($input['photo'])) { $user->updateProfilePhoto($input['photo']); - } + }*/ if ($input['email'] !== $user->email && $user instanceof MustVerifyEmail) { diff --git a/app/Console/Commands/UpdateSlugs.php b/app/Console/Commands/UpdateSlugs.php new file mode 100644 index 0000000..3626159 --- /dev/null +++ b/app/Console/Commands/UpdateSlugs.php @@ -0,0 +1,45 @@ +get() + ->each( + function (Recipe $model) { + $newName = $model->title.' 2612'; + $oldName = Str::replaceLast(' 2612', '', $newName); + + $model->title = $newName; + $model->save(); + + $model->title = $oldName; + $model->save(); + } + ); + } +} diff --git a/app/Events/ChatMessageUpdated.php b/app/Events/ChatMessageUpdated.php index 61a859b..3838763 100644 --- a/app/Events/ChatMessageUpdated.php +++ b/app/Events/ChatMessageUpdated.php @@ -12,7 +12,7 @@ class ChatMessageUpdated implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; - public $message; + public array $message; /** * Create a new event instance. diff --git a/app/Events/DietSelected.php b/app/Events/DietSelected.php index 92e1c13..24965aa 100644 --- a/app/Events/DietSelected.php +++ b/app/Events/DietSelected.php @@ -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. diff --git a/app/Http/Controllers/BlogPostController.php b/app/Http/Controllers/BlogPostController.php index a4fc97b..d3e0799 100644 --- a/app/Http/Controllers/BlogPostController.php +++ b/app/Http/Controllers/BlogPostController.php @@ -4,18 +4,14 @@ namespace App\Http\Controllers; use App\Models\BlogPost; use Illuminate\Http\Request; +use Illuminate\View\View; /* use Spatie\QueryBuilder\AllowedFilter; */ /* use Spatie\QueryBuilder\QueryBuilder; */ class BlogPostController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index(Request $request) + public function index(Request $request): View { // if ($request->has('author')) { // $author = $request->get('author'); @@ -31,31 +27,12 @@ class BlogPostController extends Controller return view('blog_post/index'); } - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() + public function create(): View { return view('blog_post/edit_form'); } - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - } - - /** - * Display the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function show(BlogPost $blogPost) + public function show(BlogPost $blogPost): View { $data['author'] = $blogPost->author()->first(); $data['tags'] = $blogPost->tags()->get(); @@ -67,34 +44,11 @@ class BlogPostController extends Controller ->cooldown($expiresAt) ->record(); - echo view('blog_post/show', $data); + return view('blog_post/show', $data); } - /** - * Show the form for editing the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function edit(BlogPost $blogPost) + public function edit(BlogPost $blogPost): View { return view('blog_post/edit_form', ['blogPost' => $blogPost]); } - - /** - * Update the specified resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function update(Request $request, BlogPost $blogPost) - { - } - - /** - * Remove the specified resource from storage. - * - * @return \Illuminate\Http\Response - */ - public function destroy(BlogPost $blogPost) - { - } } diff --git a/app/Http/Controllers/CalendarController.php b/app/Http/Controllers/CalendarController.php index 9151776..24440be 100644 --- a/app/Http/Controllers/CalendarController.php +++ b/app/Http/Controllers/CalendarController.php @@ -2,29 +2,29 @@ namespace App\Http\Controllers; -use App\Models\Calendar; use App\Models\Diary; use Carbon\Carbon; use Carbon\CarbonPeriod; -use Illuminate\Http\Request; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Illuminate\Support\Facades\Auth; 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 @@ -39,18 +39,13 @@ 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); } - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() + public function index(): View|ViewFactory { $curUser = Auth::user(); $fullGridPeriod = CarbonPeriod::create( @@ -58,8 +53,9 @@ class CalendarController extends Controller '1 day', $this->gridEndsAt ); + $filledDays = Diary::where('user_id', $curUser->id) - ->whereMonth('date', now()->month) + ->whereMonth('date', (string) now()->month) ->get() ->keyBy('date'); @@ -73,58 +69,4 @@ class CalendarController extends Controller ] ); } - - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - } - - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - } - - /** - * Display the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function show(Calendar $calendar) - { - } - - /** - * Show the form for editing the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function edit(Calendar $calendar) - { - } - - /** - * Update the specified resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function update(Request $request, Calendar $calendar) - { - } - - /** - * Remove the specified resource from storage. - * - * @return \Illuminate\Http\Response - */ - public function destroy(Calendar $calendar) - { - } } diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index b2b757c..084ceaf 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -2,67 +2,14 @@ namespace App\Http\Controllers; -use App\Events\ChatMessageUpdated; use App\Models\Chat; use App\Models\User; -use Illuminate\Http\Request; - -class ChatMessage -{ - public $id; - - public $payload; - - public function __construct($id, $payload) - { - $this->id = $id; - $this->payload = $payload; - } - - public function someRandomFillFunction() - { - $users1 = User::all()->pluck('id'); - $users2 = User::all()->pluck('id'); - $faker = Faker\Factory::create(); - - $users1->each( - function ($user1, $key) use ($faker, $users2) { - $users2->each( - function ($user2) use ($faker, $user1) { - if ($user1 === $user2) { - return; - } - $data1 = [ - 'from_user_id' => $user2, - 'to_user_id' => $user1, - 'data' => $faker->text(), - ]; - - $data2 = [ - 'from_user_id' => $user1, - 'to_user_id' => $user2, - 'data' => $faker->text(), - ]; - - $newMessage = (new Chat())->forceFill($data1); - $newMessage->save(); - $newMessage = (new Chat())->forceFill($data2); - $newMessage->save(); - } - ); - } - ); - } -} +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class ChatController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() + public function index(): View|ViewFactory { // $_ = "from_user_id to_user_id"; $curUserId = Auth()->user()->id; @@ -96,32 +43,7 @@ class ChatController extends Controller ); } - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - ChatMessageUpdated::dispatch(new ChatMessage(time(), 'some text '.md5(time()))); - } - - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - } - - /** - * Display the specified resource. - * - * @param \App\Models\Chat $chat - * @return \Illuminate\Http\Response - */ - public function show(int $lastChatUser) + public function show(int $lastChatUser): View|ViewFactory { $lastChatUser = User::find($lastChatUser); // $_ = "from_user_id to_user_id"; @@ -149,34 +71,7 @@ class ChatController extends Controller ); } - /** - * Show the form for editing the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function edit(chat $chat) - { - } - - /** - * Update the specified resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function update(Request $request, chat $chat) - { - } - - /** - * Remove the specified resource from storage. - * - * @return \Illuminate\Http\Response - */ - public function destroy(chat $chat) - { - } - - private function makeChanName($from, $to) + private function makeChanName(?int $from = null, ?int $to = null): string { return (int) $from < (int) $to ? $from.'_'.$to diff --git a/app/Http/Controllers/ConsultantController.php b/app/Http/Controllers/ConsultantController.php index 5225409..d8802f3 100644 --- a/app/Http/Controllers/ConsultantController.php +++ b/app/Http/Controllers/ConsultantController.php @@ -2,75 +2,12 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; +use Illuminate\View\View; class ConsultantController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() + public function index(): View { return view('consultant.list'); } - - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - } - - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - } - - /** - * Display the specified resource. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function show($id) - { - } - - /** - * Show the form for editing the specified resource. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function edit($id) - { - } - - /** - * Update the specified resource in storage. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function update(Request $request, $id) - { - } - - /** - * Remove the specified resource from storage. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function destroy($id) - { - } } diff --git a/app/Http/Controllers/ConsultantDiaryCommentController.php b/app/Http/Controllers/ConsultantDiaryCommentController.php index 1b2552c..0cb60cf 100644 --- a/app/Http/Controllers/ConsultantDiaryCommentController.php +++ b/app/Http/Controllers/ConsultantDiaryCommentController.php @@ -3,43 +3,11 @@ namespace App\Http\Controllers; use App\Models\Diary; -use Illuminate\Http\Request; +use Illuminate\View\View; class ConsultantDiaryCommentController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() - { - } - - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - } - - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - } - - /** - * Display the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function show(Diary $diary) + public function show(Diary $diary): View { $data = [ 'daysCount' => 1, @@ -49,12 +17,7 @@ class ConsultantDiaryCommentController extends Controller return view('diary.consultant_comments', $data); } - /** - * Show the form for editing the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function edit(Diary $diary) + public function edit(Diary $diary): View { $curMeals = $diary->meals()->orderBy('type')->get(); $typeNames = [ @@ -75,23 +38,4 @@ class ConsultantDiaryCommentController extends Controller return view('diary.consultant_comments_edit', $data); } - - /** - * Update the specified resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function update(Request $request, Diary $diary) - { - } - - /** - * Remove the specified resource from storage. - * - * @param \App\Models\Diary $consultantDiaryComment - * @return \Illuminate\Http\Response - */ - public function destroy(Diary $diary) - { - } } diff --git a/app/Http/Controllers/ConsultantRequestFormController.php b/app/Http/Controllers/ConsultantRequestFormController.php index c854131..0c0f5d1 100644 --- a/app/Http/Controllers/ConsultantRequestFormController.php +++ b/app/Http/Controllers/ConsultantRequestFormController.php @@ -3,27 +3,18 @@ namespace App\Http\Controllers; use App\Models\User; -use Illuminate\Http\Request; +use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Auth; +use Illuminate\View\View; class ConsultantRequestFormController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() + public function index(): View { return view('consultant.index'); } - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() + public function create(): View | RedirectResponse { $user = Auth::user(); $state = $user->consultant_state; @@ -40,21 +31,7 @@ class ConsultantRequestFormController extends Controller ); } - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - } - - /** - * Display the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function show(User $user) + public function show(User $user): View { $requestData = $user->consultant_request; $medicalEducations = $requestData ? json_decode($requestData->completed_courses, true) : []; @@ -72,12 +49,7 @@ class ConsultantRequestFormController extends Controller ); } - /** - * Show the form for editing the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function edit(User $user) + public function edit(User $user): View { // dd($user); // return redirect()->route('consultant_request.show', [$user]); @@ -91,22 +63,4 @@ class ConsultantRequestFormController extends Controller ] ); } - - /** - * Update the specified resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function update(Request $request, User $user) - { - } - - /** - * Remove the specified resource from storage. - * - * @return \Illuminate\Http\Response - */ - public function destroy(User $user) - { - } } diff --git a/app/Http/Controllers/DiaryController.php b/app/Http/Controllers/DiaryController.php index 9da9bd3..5fcf954 100644 --- a/app/Http/Controllers/DiaryController.php +++ b/app/Http/Controllers/DiaryController.php @@ -3,17 +3,14 @@ namespace App\Http\Controllers; use App\Models\Diary; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Illuminate\View\View; class DiaryController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() + public function index(): RedirectResponse { /* return view('diary.index'); */ $curDiary = $this->getCurrentDiary(); @@ -22,32 +19,12 @@ class DiaryController extends Controller return redirect()->route('diary.edit', $curDiary); } - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - } - - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) + public function store(Request $request): void { dd($request); } - /** - * Display the specified resource. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function show(Diary $diary) + public function show(Diary $diary): View { /* $curDiary = Diary::find($id); */ $daysCount = Diary::where('user_id', auth()->id())->count(); @@ -55,13 +32,7 @@ class DiaryController extends Controller return view('diary.show', ['curDiary' => $diary, 'daysCount' => $daysCount]); } - /** - * Show the form for editing the specified resource. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function edit($id) + public function edit(int $id): View { $curDiary = Diary::find($id); $daysCount = Diary::where('user_id', auth()->id())->count(); @@ -76,13 +47,7 @@ class DiaryController extends Controller ); } - /** - * Update the specified resource in storage. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function update(Request $request, $id) + public function update(Request $request, int $id): RedirectResponse { /* dd($request, $id, $request->input()); */ $curDiary = Diary::find($id); @@ -95,17 +60,7 @@ class DiaryController extends Controller return redirect()->route('diary.show', $id); } - /** - * Remove the specified resource from storage. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function destroy($id) - { - } - - private function getCurrentDiary() + private function getCurrentDiary(): Diary { $curUserId = Auth::id(); $curDiary = Diary::userToDayItem($curUserId)->first(); @@ -117,14 +72,14 @@ class DiaryController extends Controller return $this->newDiary($curUserId); } - private function newDiary($curUserId) + private function newDiary(int $curUserId): Diary { $curDiary = new Diary(); $curDiary->date = now()->setTimezone('3')->format('Y-m-d'); $curDiary->wakeup = '06:30'; $curDiary->retire = '22:30'; $curDiary->user_id = $curUserId; - $curDiary->closed = false; + $curDiary->closed = (int) false; $curDiary->comment = ''; $curDiary->save(); diff --git a/app/Http/Controllers/DietController.php b/app/Http/Controllers/DietController.php index bc65515..3615469 100644 --- a/app/Http/Controllers/DietController.php +++ b/app/Http/Controllers/DietController.php @@ -5,17 +5,13 @@ namespace App\Http\Controllers; use App\Models\Diet; use App\Models\User; use Illuminate\Http\Request; +use Illuminate\View\View; use Spatie\QueryBuilder\AllowedFilter; use Spatie\QueryBuilder\QueryBuilder; class DietController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index(Request $request) + public function index(Request $request): View { $hasTypes = []; if ($request->has('author')) { @@ -48,27 +44,17 @@ class DietController extends Controller ); } - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() + public function create(): View { return view('diet/edit_form'); } - public function edit(Diet $diet) + public function edit(Diet $diet): View { return view('diet/edit_form', ['diet' => $diet]); } - /** - * Display the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function show(Diet $diet) + public function show(Diet $diet): View { $expiresAt = now()->addHours(24); diff --git a/app/Http/Controllers/FeedController.php b/app/Http/Controllers/FeedController.php index ebe0d69..135fb0d 100644 --- a/app/Http/Controllers/FeedController.php +++ b/app/Http/Controllers/FeedController.php @@ -3,77 +3,15 @@ namespace App\Http\Controllers; use App\Services\FeedService; -use Illuminate\Http\Request; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class FeedController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() + public function index(): View | ViewFactory { $feed = (new FeedService())->showActualFeed(); return view('feed.index', ['posts' => $feed]); } - - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - } - - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - } - - /** - * Display the specified resource. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function show($id) - { - } - - /** - * Show the form for editing the specified resource. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function edit($id) - { - } - - /** - * Update the specified resource in storage. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function update(Request $request, $id) - { - } - - /** - * Remove the specified resource from storage. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function destroy($id) - { - } } diff --git a/app/Http/Controllers/FinanceController.php b/app/Http/Controllers/FinanceController.php index b9373f9..829928d 100644 --- a/app/Http/Controllers/FinanceController.php +++ b/app/Http/Controllers/FinanceController.php @@ -2,71 +2,6 @@ namespace App\Http\Controllers; -use App\Models\Finance; -use Illuminate\Http\Request; - class FinanceController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() - { - } - - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - } - - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - } - - /** - * Display the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function show(Finance $finance) - { - } - - /** - * Show the form for editing the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function edit(Finance $finance) - { - } - - /** - * Update the specified resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function update(Request $request, Finance $finance) - { - } - - /** - * Remove the specified resource from storage. - * - * @return \Illuminate\Http\Response - */ - public function destroy(Finance $finance) - { - } } diff --git a/app/Http/Controllers/PlanController.php b/app/Http/Controllers/PlanController.php index 8102475..3de2390 100644 --- a/app/Http/Controllers/PlanController.php +++ b/app/Http/Controllers/PlanController.php @@ -4,16 +4,13 @@ namespace App\Http\Controllers; use App\Models\Plan; use App\Models\User; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Illuminate\Http\Request; class PlanController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index(Request $request) + public function index(Request $request): View|ViewFactory { if ($request->has('author')) { $author = $request->get('author'); @@ -26,31 +23,12 @@ class PlanController extends Controller return view('plan/index', ['plans' => $plans]); } - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() + public function create(): View|ViewFactory { return view('plan/edit_form'); } - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - } - - /** - * Display the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function show(Plan $plan) + public function show(Plan $plan): View|ViewFactory { $expiresAt = now()->addHours(24); @@ -58,58 +36,11 @@ class PlanController extends Controller ->cooldown($expiresAt) ->record(); - // $options1 = $this->unserializeOptions($plan->packet1_options); - // $options2 = $this->unserializeOptions($plan->packet2_options); - // $options3 = $this->unserializeOptions($plan->packet2_options); - // $options1 = $plan->packet1_options; - // $options2 = $plan->packet2_options; - // $options3 = $plan->packet2_options; - - return view( - 'plan/show', - [ - 'plan' => $plan, - // 'options1' => $options1, - // 'options2' => $options2, - // 'options3' => $options3, - ] - ); + return view('plan/show', ['plan' => $plan]); } - /** - * Show the form for editing the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function edit(Plan $plan) + public function edit(Plan $plan): View|ViewFactory { return view('plan/edit_form', ['plan' => $plan]); } - - /** - * Update the specified resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function update(Request $request, Plan $plan) - { - } - - /** - * Remove the specified resource from storage. - * - * @return \Illuminate\Http\Response - */ - public function destroy(Plan $plan) - { - } - - private function unserializeOptions($str) - { - if (preg_match('/^".*"$/', $str)) { - return json_decode(stripslashes(mb_substr($str, 1, -1)), true); - } - - return json_decode(stripslashes($str), true); - } } diff --git a/app/Http/Controllers/ProductNutritionalValueController.php b/app/Http/Controllers/ProductNutritionalValueController.php index 37fdb65..4c5d2ac 100644 --- a/app/Http/Controllers/ProductNutritionalValueController.php +++ b/app/Http/Controllers/ProductNutritionalValueController.php @@ -3,35 +3,22 @@ namespace App\Http\Controllers; use App\Models\ProductNutritionalValue; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class ProductNutritionalValueController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() + public function index(): View|ViewFactory { return view('product_nutritional/index'); } - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() + public function create(): View|ViewFactory { return view('product_nutritional/create'); } - /** - * Display the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function show(ProductNutritionalValue $productNutritionalValue) + public function show(ProductNutritionalValue $productNutritionalValue): View|ViewFactory { return view( 'product_nutritional/show', @@ -39,22 +26,8 @@ class ProductNutritionalValueController extends Controller ); } - /** - * Show the form for editing the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function edit(ProductNutritionalValue $productNutritionalValue) + public function edit(ProductNutritionalValue $productNutritionalValue): View|ViewFactory { return view('product_nutritional/edit', ['productNutritionalValue' => $productNutritionalValue]); } - - /** - * Remove the specified resource from storage. - * - * @return \Illuminate\Http\Response - */ - public function destroy(ProductNutritionalValue $productNutritionalValue) - { - } } diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 70a37dc..987cfdb 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -3,18 +3,13 @@ namespace App\Http\Controllers; use App\Models\User; -use App\Models\UserDetailz; -use Illuminate\Http\Request; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Illuminate\Support\Facades\Auth; class ProfileController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() + public function index(): View|ViewFactory { $user = Auth::user(); $userPosts = $user @@ -41,30 +36,7 @@ class ProfileController extends Controller ); } - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - } - - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - } - - /** - * Display the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function show(User $user) + public function show(User $user): View|ViewFactory { $expiresAt = now()->addHours(24); $userPosts = $user @@ -94,31 +66,4 @@ class ProfileController extends Controller ] ); } - - /** - * Show the form for editing the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function edit(UserDetailz $userDetailz) - { - } - - /** - * Update the specified resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function update(Request $request, UserDetailz $userDetailz) - { - } - - /** - * Remove the specified resource from storage. - * - * @return \Illuminate\Http\Response - */ - public function destroy(UserDetailz $userDetailz) - { - } } diff --git a/app/Http/Controllers/RecipeController.php b/app/Http/Controllers/RecipeController.php index e0f463b..e611c8c 100644 --- a/app/Http/Controllers/RecipeController.php +++ b/app/Http/Controllers/RecipeController.php @@ -3,35 +3,22 @@ namespace App\Http\Controllers; use App\Models\Recipe; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class RecipeController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() + public function index(): View|ViewFactory { return view('recipe/index'); } - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() + public function create(): View|ViewFactory { return view('recipe/edit_form'); } - /** - * Display the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function show(Recipe $recipe) + public function show(Recipe $recipe): View|ViewFactory { $data = [ 'author' => $recipe->author()->first(), @@ -48,12 +35,7 @@ class RecipeController extends Controller return view('recipe/show', $data); } - /** - * Show the form for editing the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function edit(Recipe $recipe) + public function edit(Recipe $recipe): View|ViewFactory { return view('recipe/edit_form', ['recipe' => $recipe]); } diff --git a/app/Http/Controllers/RegistrationStartController.php b/app/Http/Controllers/RegistrationStartController.php index 97f49b4..7f6629d 100644 --- a/app/Http/Controllers/RegistrationStartController.php +++ b/app/Http/Controllers/RegistrationStartController.php @@ -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(); diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 6124dd0..0a5922b 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -3,72 +3,13 @@ namespace App\Http\Controllers; use App\Models\User; -use App\Models\UserDetailz; -use Illuminate\Http\Request; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class UserController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() - { - } - - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - } - - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - } - - /** - * Display the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function show(User $user) - { - /* return view('user.show', ['user' => $user]); */ - } - - /** - * Show the form for editing the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function edit(UserDetailz $userDetailz) - { - } - - /** - * Update the specified resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function update(Request $request, UserDetailz $userDetailz) - { - } - - /** - * Remove the specified resource from storage. - * - * @return \Illuminate\Http\Response - */ - public function destroy(UserDetailz $userDetailz) + public function show(User $user): View|ViewFactory { + return view('user.show', ['user' => $user]); } } diff --git a/app/Http/Controllers/UserDetailzController.php b/app/Http/Controllers/UserDetailzController.php index f986146..02d8d6f 100644 --- a/app/Http/Controllers/UserDetailzController.php +++ b/app/Http/Controllers/UserDetailzController.php @@ -3,44 +3,12 @@ namespace App\Http\Controllers; use App\Models\UserDetailz; -use Illuminate\Http\Request; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; class UserDetailzController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() - { - } - - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - } - - /** - * Store a newly created resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - } - - /** - * Display the specified resource. - * - * @param \App\Models\User $user - * @return \Illuminate\Http\Response - */ - public function show(UserDetailz $userDetailz) + public function show(UserDetailz $userDetailz): View|ViewFactory { $regFormKeys = [ 'first_name' => __('reg_form.first_name'), @@ -82,12 +50,7 @@ class UserDetailzController extends Controller ); } - /** - * Show the form for editing the specified resource. - * - * @return \Illuminate\Http\Response - */ - public function edit(UserDetailz $userDetailz) + public function edit(UserDetailz $userDetailz): View|ViewFactory { $regFormKeys = [ 'first_name' => __('reg_form.first_name'), @@ -152,22 +115,4 @@ class UserDetailzController extends Controller ] ); } - - /** - * Update the specified resource in storage. - * - * @return \Illuminate\Http\Response - */ - public function update(Request $request, UserDetailz $userDetailz) - { - } - - /** - * Remove the specified resource from storage. - * - * @return \Illuminate\Http\Response - */ - public function destroy(UserDetailz $userDetailz) - { - } } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index bbbb073..d714ca7 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -53,7 +53,7 @@ class Kernel extends HttpKernel * * @var array */ - protected $routeMiddleware = [ + protected $middlewareAliases = [ 'auth' => \App\Http\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 704089a..752ef1f 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -10,6 +10,7 @@ class Authenticate extends Middleware * Get the path the user should be redirected to when they are not authenticated. * * @param \Illuminate\Http\Request $request + * * @return string|null */ protected function redirectTo($request) diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index 4e7c24b..6c4df6a 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -14,6 +14,7 @@ class RedirectIfAuthenticated * * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next * @param string|null ...$guards + * * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse */ public function handle(Request $request, Closure $next, ...$guards) diff --git a/app/Listeners/ProcessDietSelectedNotification.php b/app/Listeners/ProcessDietSelectedNotification.php index c09fc4c..0473820 100644 --- a/app/Listeners/ProcessDietSelectedNotification.php +++ b/app/Listeners/ProcessDietSelectedNotification.php @@ -12,23 +12,9 @@ class ProcessDietSelectedNotification implements ShouldQueue { use InteractsWithQueue; - public $afterCommit = true; + public bool $afterCommit = true; - /** - * Create the event listener. - * - * @return void - */ - public function __construct() - { - } - - /** - * Handle the event. - * - * @return void - */ - public function handle(DietSelected $event) + public function handle(DietSelected $event): void { $user = $event->user; $diet = $event->diet; diff --git a/app/Livewire/BlogPost/Comment/Create.php b/app/Livewire/BlogPost/Comment/Create.php index ef84721..27325ad 100644 --- a/app/Livewire/BlogPost/Comment/Create.php +++ b/app/Livewire/BlogPost/Comment/Create.php @@ -5,6 +5,7 @@ namespace App\Livewire\BlogPost\Comment; use App\Models\BlogPost; use App\Models\BlogPostComment; use App\Models\User; +use Illuminate\View\View; use Livewire\Component; class Create extends Component @@ -13,16 +14,16 @@ class Create extends Component public User $user; - public $body = ''; + public string $body = ''; - public $grade = 0; + public string|int $grade = 0; - public function render() + public function render(): View { return view('livewire.blog-post.comment.create'); } - public function save() + public function save(): void { $comment = new BlogPostComment(); $comment->grade = $this->grade; diff --git a/app/Livewire/BlogPost/Comment/Show.php b/app/Livewire/BlogPost/Comment/Show.php index 1efdb24..0cf4bb4 100644 --- a/app/Livewire/BlogPost/Comment/Show.php +++ b/app/Livewire/BlogPost/Comment/Show.php @@ -3,16 +3,20 @@ namespace App\Livewire\BlogPost\Comment; use App\Models\BlogPost; +use Illuminate\View\View; use Livewire\Component; class Show extends Component { public BlogPost $blogPost; - protected $listeners = ['commentAdded' => '$refresh']; - - public function render() + public function render(): View { return view('livewire.blog-post.comment.show'); } + + protected function getListeners(): array + { + return ['commentAdded' => '$refresh']; + } } diff --git a/app/Livewire/BlogPost/Comment/Upvote.php b/app/Livewire/BlogPost/Comment/Upvote.php index 600776e..0590029 100644 --- a/app/Livewire/BlogPost/Comment/Upvote.php +++ b/app/Livewire/BlogPost/Comment/Upvote.php @@ -3,18 +3,19 @@ namespace App\Livewire\BlogPost\Comment; use App\Models\BlogPostComment; +use Illuminate\View\View; use Livewire\Component; class Upvote extends Component { public BlogPostComment $comment; - public function mount(BlogPostComment $comment) + public function mount(BlogPostComment $comment): void { $this->comment = $comment; } - public function render() + public function render(): View { $upvotes = $this->comment->upvotes()->forBlogPostCommentsUpVote($this->comment)->count(); $downvotes = $this->comment->upvotes()->forBlogPostCommentsDownVote($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(); diff --git a/app/Livewire/BlogPost/Create.php b/app/Livewire/BlogPost/Create.php index c6920ac..7fa86f1 100644 --- a/app/Livewire/BlogPost/Create.php +++ b/app/Livewire/BlogPost/Create.php @@ -4,7 +4,10 @@ namespace App\Livewire\BlogPost; use App\Models\BlogPost; use App\Models\Tag; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Auth; +use Illuminate\View\View; use Livewire\Component; use Livewire\WithFileUploads; @@ -12,56 +15,55 @@ class Create extends Component { use WithFileUploads; - public $image = null; + public UploadedFile|null $image = null; - public $state = 'archived'; + public string $state = 'archived'; - public $title = ''; + public string $title = ''; - public $description = ''; + public string $description = ''; - public $tags = []; + public Collection|array $tags = []; - public $videoUrl = ''; + public string $videoUrl = ''; - protected $listeners = ['parentComponentTagAdded', 'parentComponentTagRemoved']; - - public function render() + public function render(): View { return view('livewire.blog-post.create'); } - public function parentComponentTagAdded(Tag $tag) + public function parentComponentTagAdded(Tag $tag): void { $tagIndex = $tag->id; $this->tags[$tagIndex] = $tag; } - public function parentComponentTagRemoved($tag) + public function parentComponentTagRemoved(Tag $tag): void { $this->tags = collect($this->tags) ->filter(fn ($curTag) => $curTag['name'] !== $tag) ->all(); } - public function draft() + public function draft(): void { $this->state = 'archived'; $this->publish(); } - public function preview() + public function preview(): void { $this->state = 'archived'; $this->publish(); } - public function publish() + public function publish(): void { $this->validate(); $post = new BlogPost(); - $post->image = $this->image->store('blog_posts', 'public'); + // $post->image = $this->image->store('blog_posts', 'public'); + $post->image = $this->image->store('blog_posts'); $post->state = $this->state; $post->title = $this->title; $post->description = $this->description; @@ -74,10 +76,18 @@ class Create extends Component $user = Auth::user(); $user->author_of_blog_post()->attach($post->id); - return redirect()->route('blog_post.show', $post->id); + $this->redirectRoute('blog_post.show', $post); + // return redirect()->route('blog_post.show', $post->id); } - protected function rules() + // protected $listeners = ['parentComponentTagAdded', 'parentComponentTagRemoved']; + + protected function getListeners(): array + { + return ['parentComponentTagAdded', 'parentComponentTagRemoved']; + } + + protected function rules(): array { return [ 'image' => 'required|image|max:2048', diff --git a/app/Livewire/BlogPost/Edit.php b/app/Livewire/BlogPost/Edit.php index 5357862..cc2b3cf 100644 --- a/app/Livewire/BlogPost/Edit.php +++ b/app/Livewire/BlogPost/Edit.php @@ -4,7 +4,10 @@ namespace App\Livewire\BlogPost; use App\Models\BlogPost; use App\Models\Tag; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Auth; +use Illuminate\View\View; use Livewire\Component; use Livewire\WithFileUploads; @@ -14,23 +17,21 @@ class Edit extends Component public BlogPost $blogPost; - public $image = null; + public string|UploadedFile $image; - public $state = 'archived'; + public string $state = 'archived'; - public $title = ''; + public string $title = ''; - public $description = ''; + public string $description = ''; - public $tags = []; + public Collection|array $tags = []; - public $videoUrl = ''; + public string $videoUrl = ''; - protected $listeners = ['blogPostTagAdded', 'blogPostTagRemoved']; - - public function mount(BlogPost $blogPost) + public function mount(BlogPost $blogPost): void { - $this->name = $blogPost->name; + // $this->name = $blogPost->name; $this->image = $blogPost->image; $this->state = $blogPost->state; $this->title = $blogPost->title; @@ -39,13 +40,13 @@ class Edit extends Component $this->videoUrl = $blogPost->youtube_url; } - public function parentComponentTagAdded(Tag $tag) + public function parentComponentTagAdded(Tag $tag): void { $tagIndex = $tag->id; $this->tags[$tagIndex] = $tag; } - public function parentComponentTagRemoved($tag) + public function parentComponentTagRemoved(Tag $tag): void { $tagToDetach = Tag::where('name', $tag)->first(); $this->tags = collect($this->tags) @@ -55,24 +56,24 @@ class Edit extends Component $this->blogPost->tags()->detach($tagToDetach->id); } - public function draft() + public function draft(): void { $this->state = 'archived'; $this->publish(); } - public function preview() + public function preview(): void { $this->state = 'archived'; $this->publish(); } - public function publish() + public function publish(): void { $this->validate(); $post = $this->blogPost; - /* $post->image = $this->image->store('blog_posts', 'public'); */ + $post->image = ! is_string($this->image) ? $this->image->store('blog_posts') : $this->image; $post->state = $this->state; $post->title = $this->title; $post->description = $this->description; @@ -88,15 +89,20 @@ class Edit extends Component $user = Auth::user(); $user->author_of_blog_post()->attach($post->id); - return redirect()->route('blog_post.show', $post->id); + $this->redirectRoute('blog_post.show', $post); } - public function render() + public function render(): View { return view('livewire.blog-post.edit'); } - protected function rules() + protected function getListeners(): array + { + return ['blogPostTagAdded', 'blogPostTagRemoved']; + } + + protected function rules(): array { return [ /* 'image' => 'required|image|max:2048', */ diff --git a/app/Livewire/BlogPost/Like.php b/app/Livewire/BlogPost/Like.php index be27bab..e8b84a9 100644 --- a/app/Livewire/BlogPost/Like.php +++ b/app/Livewire/BlogPost/Like.php @@ -3,20 +3,21 @@ namespace App\Livewire\BlogPost; use App\Models\BlogPost; +use Illuminate\View\View; use Livewire\Component; class Like extends Component { public BlogPost $blogPost; - public $isIconOnly = false; + public bool $isIconOnly = false; - public function mount(BlogPost $blogPost) + public function mount(BlogPost $blogPost): void { $this->blogPost = $blogPost; } - public function render() + public function render(): View { return view('livewire.blog-post.like'); } diff --git a/app/Livewire/BlogPost/LikeCount.php b/app/Livewire/BlogPost/LikeCount.php index 7ab9525..c0bbf43 100644 --- a/app/Livewire/BlogPost/LikeCount.php +++ b/app/Livewire/BlogPost/LikeCount.php @@ -3,24 +3,28 @@ namespace App\Livewire\BlogPost; use App\Models\BlogPost; +use Illuminate\View\View; use Livewire\Component; class LikeCount extends Component { public BlogPost $blogPost; - protected $listeners = ['liked' => '$refresh']; - - public function mount(BlogPost $blogPost) + public function mount(BlogPost $blogPost): void { $this->blogPost = $blogPost; } - public function render() + public function render(): View { return view( 'livewire.blog-post.like-count', ['count' => $this->blogPost->likes_count] ); } + + protected function getListeners(): array + { + return ['liked' => '$refresh']; + } } diff --git a/app/Livewire/BlogPost/ListView.php b/app/Livewire/BlogPost/ListView.php index d412e58..bde3fa9 100644 --- a/app/Livewire/BlogPost/ListView.php +++ b/app/Livewire/BlogPost/ListView.php @@ -6,6 +6,7 @@ use App\Models\BlogPost; use App\Models\Tag; use App\Models\User; use Illuminate\Support\Str; +use Illuminate\View\View; use Livewire\Component; use Livewire\WithPagination; @@ -13,22 +14,22 @@ class ListView extends Component { use WithPagination; - public $search = ''; + public string $search = ''; - public $typeFilter = 'all'; + public string $typeFilter = 'all'; - public $tag = ''; + public string $tag = ''; - public $author; + public User|null $author = null; - protected $queryString = [ + protected array $queryString = [ 'search' => ['except' => ''], 'typeFilter' => ['except' => 'all'], 'tag' => ['except' => ''], 'author' => ['except' => ''], ]; - public function render() + public function render(): View { if ($this->author) { $author = $this->author; diff --git a/app/Livewire/Chat/LastUsers.php b/app/Livewire/Chat/LastUsers.php index 3330329..2895f76 100644 --- a/app/Livewire/Chat/LastUsers.php +++ b/app/Livewire/Chat/LastUsers.php @@ -2,27 +2,30 @@ namespace App\Livewire\Chat; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Support\Collection; use Livewire\Component; class LastUsers extends Component { - public $lastChatUsers; + public Collection $lastChatUsers; - public $activeUserId; + public ?int $activeUserId = null; - public $curUserId; + public int $curUserId; - public $chanId; + public string $chanId; - public function render() + public function render(): View|ViewFactory { 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'); - redirect()->route('chat.show', $id); + $this->redirectRoute('chat.show', $id); } } diff --git a/app/Livewire/Chat/MessageWindow.php b/app/Livewire/Chat/MessageWindow.php index 29b5d26..29a54ad 100644 --- a/app/Livewire/Chat/MessageWindow.php +++ b/app/Livewire/Chat/MessageWindow.php @@ -5,25 +5,28 @@ namespace App\Livewire\Chat; use App\Events\ChatMessageUpdated; use App\Models\Chat; use App\Models\User; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Support\Collection; 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 $recipientUserId = null; - public $recipientUser; + public ?User $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 +36,7 @@ class MessageWindow extends Component ]; } - public function notifyNewMessage($e): void + public function notifyNewMessage(array $e): void { $message = $e['message']; @@ -41,11 +44,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 +61,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); @@ -68,18 +71,18 @@ class MessageWindow extends Component // ? $recipientUserId . "_" . $this->curUserId // : $this->curUserId . "_" . $recipientUserId; if (is_null($recipientUserId)) { - $this->messages = []; + $this->messages = collect([]); } else { $this->messages = (new Chat())->withLastTenMessages($this->curUserId, $recipientUserId)->get(); } } - public function render() + public function render(): View|ViewFactory { return view('livewire.chat.message-window'); } - public function sendChatMessage() + public function sendChatMessage(): void { $chatMessage = [ 'data' => $this->curMessage, diff --git a/app/Livewire/Chat/Tracker.php b/app/Livewire/Chat/Tracker.php index e5274f9..b9156a4 100644 --- a/app/Livewire/Chat/Tracker.php +++ b/app/Livewire/Chat/Tracker.php @@ -2,25 +2,29 @@ namespace App\Livewire\Chat; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\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|ViewFactory { return view('livewire.chat.tracker'); } + + protected function getListeners(): array + { + return ['echo:direct-chat,ChatMessageUpdated' => 'notifyNewMessage']; + } } diff --git a/app/Livewire/Consultant/ListConsultants.php b/app/Livewire/Consultant/ListConsultants.php index f4d9be6..ef10c29 100644 --- a/app/Livewire/Consultant/ListConsultants.php +++ b/app/Livewire/Consultant/ListConsultants.php @@ -3,11 +3,13 @@ namespace App\Livewire\Consultant; use App\Models\ConsultantEducation; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class ListConsultants extends Component { - public function render() + public function render(): View|ViewFactory { return view( 'livewire.consultant.list-consultants', diff --git a/app/Livewire/Consultant/RegistrationForm.php b/app/Livewire/Consultant/RegistrationForm.php index 26b7dff..d4fee7f 100644 --- a/app/Livewire/Consultant/RegistrationForm.php +++ b/app/Livewire/Consultant/RegistrationForm.php @@ -6,6 +6,9 @@ use App\Models\ConsultantEducation; use App\Models\User; use App\Models\UserAttachment; use App\Notifications\ConsultantRequestStarted; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Storage; use Livewire\Component; @@ -27,15 +30,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 +49,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 +64,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|ViewFactory { return view('livewire.consultant.registration-form'); } - public function addEducation() + public function addEducation(): void { $this->validate(); $medicalEducations = $this->medicalEducations; @@ -91,7 +94,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 +107,7 @@ class RegistrationForm extends Component $this->medicalEducations = array_values($filteredEducations); } - public function save() + public function save(): void { $data = [ 'user_id' => $this->user->id, @@ -142,7 +145,7 @@ class RegistrationForm extends Component $newFile = UserAttachment::updateOrCreate( $fileData, [ - 'path' => preg_replace("/public\//xi", '/storage/', $curCert), + 'path' => preg_replace('/public\//xi', '/storage/', $curCert), 'specs' => json_encode( [ 'ext' => $photo->extension(), @@ -158,7 +161,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); diff --git a/app/Livewire/Counter.php b/app/Livewire/Counter.php index 4ea663a..6a553e7 100644 --- a/app/Livewire/Counter.php +++ b/app/Livewire/Counter.php @@ -2,23 +2,28 @@ namespace App\Livewire; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class Counter extends Component { + /** + * @var int + */ public $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|ViewFactory { return view('livewire.counter'); } diff --git a/app/Livewire/Diary/ConsultantCommentsEdit.php b/app/Livewire/Diary/ConsultantCommentsEdit.php index 5cfaea8..6d2d08a 100644 --- a/app/Livewire/Diary/ConsultantCommentsEdit.php +++ b/app/Livewire/Diary/ConsultantCommentsEdit.php @@ -3,36 +3,40 @@ namespace App\Livewire\Diary; use App\Models\ConsultantDiaryComment; +use App\Models\Diary; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; 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 +47,7 @@ class ConsultantCommentsEdit extends Component )->pluck('comment', 'comment_type')->toArray(); } - public function render() + public function render(): ViewFactory|View { $commentTypes = ['breakfast', 'dinner', 'supper', 'lunch', 'snacks', 'wakeup_time', 'total']; @@ -55,7 +59,7 @@ class ConsultantCommentsEdit extends Component ); } - public function save() + public function save(): void { foreach ($this->comments as $key => $comment) { $updateComment = ConsultantDiaryComment::updateOrCreate( diff --git a/app/Livewire/Diary/MealPhotos.php b/app/Livewire/Diary/MealPhotos.php index 8c8f039..7f7429d 100644 --- a/app/Livewire/Diary/MealPhotos.php +++ b/app/Livewire/Diary/MealPhotos.php @@ -4,6 +4,8 @@ namespace App\Livewire\Diary; use App\Models\Meal; use App\Models\UserAttachment; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Illuminate\Support\Facades\Auth; use Livewire\Component; use Livewire\WithFileUploads; @@ -14,9 +16,9 @@ class MealPhotos extends Component public Meal $meal; - public $tmpMealPhotos = []; + public array $tmpMealPhotos = []; - public function render() + public function render(): View|ViewFactory { return view( 'livewire.diary.meal-photos', @@ -26,7 +28,7 @@ class MealPhotos extends Component ); } - public function updatedTmpMealPhotos($values) + public function updatedTmpMealPhotos(array $values): void { /* dd($values); */ $newPhotos = collect($values)->take(3); diff --git a/app/Livewire/Diet/Comment/Create.php b/app/Livewire/Diet/Comment/Create.php index 8d12ba9..83ddc78 100644 --- a/app/Livewire/Diet/Comment/Create.php +++ b/app/Livewire/Diet/Comment/Create.php @@ -5,6 +5,8 @@ namespace App\Livewire\Diet\Comment; use App\Models\Diet; use App\Models\DietComment; use App\Models\User; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class Create extends Component @@ -13,23 +15,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|ViewFactory { 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(); diff --git a/app/Livewire/Diet/Comment/Show.php b/app/Livewire/Diet/Comment/Show.php index efde860..f9fb9ed 100644 --- a/app/Livewire/Diet/Comment/Show.php +++ b/app/Livewire/Diet/Comment/Show.php @@ -3,16 +3,21 @@ namespace App\Livewire\Diet\Comment; use App\Models\Diet; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class Show extends Component { public Diet $diet; - protected $listeners = ['commentAdded' => '$refresh']; - - public function render() + public function render(): View|ViewFactory { return view('livewire.diet.comment.show'); } + + protected function getListeners(): array + { + return ['commentAdded' => '$refresh']; + } } diff --git a/app/Livewire/Diet/Comment/Upvote.php b/app/Livewire/Diet/Comment/Upvote.php index f314d97..f88f9a9 100644 --- a/app/Livewire/Diet/Comment/Upvote.php +++ b/app/Livewire/Diet/Comment/Upvote.php @@ -3,18 +3,20 @@ namespace App\Livewire\Diet\Comment; use App\Models\DietComment; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\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|ViewFactory { $upvotes = $this->comment->upvotes()->forDietCommentsUpVote($this->comment)->count(); $downvotes = $this->comment->upvotes()->forDietCommentsDownVote($this->comment)->count(); @@ -30,7 +32,7 @@ class Upvote extends Component ); } - public function upvote() + public function upvote(): void { if ($this->comment->isUpVoted()) { $this->comment->removeUpVote(); @@ -49,7 +51,7 @@ class Upvote extends Component ]); } - public function downvote() + public function downvote(): void { if ($this->comment->isDownVoted()) { $this->comment->removeDownVote(); diff --git a/app/Livewire/Diet/Create.php b/app/Livewire/Diet/Create.php index 8861c85..90b98ad 100644 --- a/app/Livewire/Diet/Create.php +++ b/app/Livewire/Diet/Create.php @@ -3,6 +3,9 @@ namespace App\Livewire\Diet; use App\Models\Diet; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Auth; use Livewire\Component; use Livewire\WithFileUploads; @@ -11,86 +14,90 @@ class Create extends Component { use WithFileUploads; - public $name = ''; + public string $name = ''; - public $image = null; + public ?UploadedFile $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 = null; + public string $copyedDay; - public $copyedDayData = null; + public array $copyedDayData; - protected $listeners = ['dayUpdated', 'makeCopy', 'makePaste']; - - public function render() + public function render(): View|ViewFactory { 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); + // 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', ]; diff --git a/app/Livewire/Diet/DayEdit.php b/app/Livewire/Diet/DayEdit.php index 977337d..74234f3 100644 --- a/app/Livewire/Diet/DayEdit.php +++ b/app/Livewire/Diet/DayEdit.php @@ -2,38 +2,38 @@ namespace App\Livewire\Diet; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\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|ViewFactory { return view('livewire.diet.day-edit'); } - public function addPortion($type) + public function addPortion(string $type): void { $this->validate(); $newData = [ @@ -49,7 +49,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 +61,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 +80,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 +89,9 @@ class DayEdit extends Component $this->dispatch('dayUpdated', dayIndex: $this->day, data: $this->portions); } } + + protected function getListeners(): array + { + return ['takePaste']; + } } diff --git a/app/Livewire/Diet/Edit.php b/app/Livewire/Diet/Edit.php index 3439fd0..c5777af 100644 --- a/app/Livewire/Diet/Edit.php +++ b/app/Livewire/Diet/Edit.php @@ -3,72 +3,76 @@ namespace App\Livewire\Diet; use App\Models\Diet; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Http\UploadedFile; use Livewire\Component; +use Livewire\WithFileUploads; class Edit extends Component { + use WithFileUploads; + public Diet $diet; - public $name = ''; + public string $name = ''; - public $image = null; + 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 = null; + public string $copyedDay; - public $copyedDayData = null; + 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|ViewFactory { 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 +82,7 @@ class Edit extends Component )->to('diet.day-edit'); } - public function publish() + public function publish(): void { $this->validate(); @@ -86,26 +90,29 @@ class Edit extends Component $diet->name = $this->name; /* $diet->image = $this->image->store('diets', 'public'); */ + $diet->image = ! is_string($this->image) ? $this->image->store('diets') : $this->image; $diet->duration = $this->duration; $diet->state = $this->state; - $diet->type = json_encode($this->type); + $diet->type = $this->type; $diet->details = $this->details; - $diet->daily_schedule = json_encode($this->days); + $diet->daily_schedule = $this->days; $diet->save(); - /* $user = Auth::user(); */ - /* $user->author_of_diets()->attach($diet->id); */ - - return redirect()->route('diet.show', $diet->id); + $this->redirectRoute('diet.show', $diet); } - 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', ]; diff --git a/app/Livewire/Diet/Like.php b/app/Livewire/Diet/Like.php index 499fe4d..b62b592 100644 --- a/app/Livewire/Diet/Like.php +++ b/app/Livewire/Diet/Like.php @@ -3,20 +3,22 @@ namespace App\Livewire\Diet; use App\Models\Diet; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\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|ViewFactory { return view('livewire.diet.like'); } diff --git a/app/Livewire/Diet/LikeCount.php b/app/Livewire/Diet/LikeCount.php index 6c39f42..b9f368c 100644 --- a/app/Livewire/Diet/LikeCount.php +++ b/app/Livewire/Diet/LikeCount.php @@ -3,20 +3,19 @@ namespace App\Livewire\Diet; use App\Models\Diet; +use Illuminate\View\View; use Livewire\Component; class LikeCount extends Component { public Diet $diet; - protected $listeners = ['liked' => '$refresh']; - - 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-count', @@ -25,4 +24,9 @@ class LikeCount extends Component ] ); } + + protected function getListeners(): array + { + return ['liked' => '$refresh']; + } } diff --git a/app/Livewire/Diet/StartButton.php b/app/Livewire/Diet/StartButton.php index dd807f5..eb94530 100644 --- a/app/Livewire/Diet/StartButton.php +++ b/app/Livewire/Diet/StartButton.php @@ -5,6 +5,8 @@ namespace App\Livewire\Diet; use App\Events\DietSelected; use App\Models\Diet; use App\Models\User; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class StartButton extends Component @@ -13,19 +15,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|ViewFactory { return view('livewire.diet.start-button'); } - public function start() + public function start(): void { DietSelected::dispatch( $this->diet, @@ -33,7 +35,7 @@ class StartButton extends Component ); } - public function getLastState() + public function getLastState(): void { $this->chosenDietState = data_get($this->user->chosen_diet, 'last_state', 'oops'); } diff --git a/app/Livewire/Feed/Index.php b/app/Livewire/Feed/Index.php index ee3d22f..c508964 100644 --- a/app/Livewire/Feed/Index.php +++ b/app/Livewire/Feed/Index.php @@ -2,13 +2,15 @@ namespace App\Livewire\Feed; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class Index extends Component { - public $posts; + public array $posts; - public function render() + public function render(): View|ViewFactory { return view('livewire.feed.index'); } diff --git a/app/Livewire/Forms/ProfileEditDetailzForm.php b/app/Livewire/Forms/ProfileEditDetailzForm.php index 43c36a1..4a1b3aa 100644 --- a/app/Livewire/Forms/ProfileEditDetailzForm.php +++ b/app/Livewire/Forms/ProfileEditDetailzForm.php @@ -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']) diff --git a/app/Livewire/MealForm.php b/app/Livewire/MealForm.php index a3e060b..818ffa2 100644 --- a/app/Livewire/MealForm.php +++ b/app/Livewire/MealForm.php @@ -5,45 +5,45 @@ namespace App\Livewire; use App\Models\Diary; use App\Models\Meal; use App\Models\Portion; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\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 array $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 +65,7 @@ class MealForm extends Component $this->portions = $curPortions; } - public function updatingType($value) + public function updatingType(string $value): void { $curMeal = $this->diary->meals->where('type', $value)->first(); $this->satiety = $curMeal->satiety ?? 3; @@ -73,7 +73,7 @@ class MealForm extends Component $this->time = $curMeal->time ?? now()->setTimezone('3')->format('H:i'); } - public function render() + public function render(): View|ViewFactory { $types = [0, 1, 2, 3, 4]; $typeNames = ['Завтрак', 'Обед', 'Ужин', 'Ланч', 'Перекусы']; @@ -99,7 +99,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 +142,7 @@ class MealForm extends Component $this->dispatch('food-intake-updated')->self(); } - public function addPortion() + public function addPortion(): void { $this->validate(); @@ -159,7 +159,7 @@ class MealForm extends Component $this->reset(['product_name', 'quantity', 'portion']); } - public function editPortion($key, $item) + public function editPortion(string $key, array $item): void { $filed = [ 'product_name' => $item['product_name'], @@ -170,7 +170,7 @@ class MealForm extends Component $this->fill($filed); } - public function delPortion($key, $item) + public function delPortion(string $key, array $item): void { if (isset($item['id'])) { Portion::find($item['id'])->delete(); @@ -186,7 +186,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(); diff --git a/app/Livewire/Plan/Accordion.php b/app/Livewire/Plan/Accordion.php index aa8aed7..7e096e8 100644 --- a/app/Livewire/Plan/Accordion.php +++ b/app/Livewire/Plan/Accordion.php @@ -3,36 +3,48 @@ namespace App\Livewire\Plan; use App\Models\Plan; +use Illuminate\View\View; use Livewire\Component; class Accordion extends Component { public Plan $plan; - public $accordionState = ['options1' => true, 'options2' => false, 'options3' => false]; + public array $accordionState = ['options1' => true, 'options2' => false, 'options3' => false]; - public $options1; + public array $options1; - public $options2; + public array $options2; - public $options3; + public array $options3; public function mount(Plan $plan): void { $this->plan = $plan; - // dd($this->unserializeOptions($plan->packet3_options)); - $this->options1 = $plan->packet1_options; - $this->options2 = $plan->packet2_options; - $this->options3 = $plan->packet3_options; + $this->options1['items'] = $this->filter_not_empty_items($plan->packet1_options['items'] ?? []); + $this->options2['items'] = $this->filter_not_empty_items($plan->packet2_options['items'] ?? []); + $this->options3['items'] = $this->filter_not_empty_items($plan->packet3_options['items'] ?? []); + + $this->options1['price'] = $plan->packet1_options['price'] ?? 0; + $this->options2['price'] = $plan->packet2_options['price'] ?? 0; + $this->options3['price'] = $plan->packet3_options['price'] ?? 0; + + $this->options1['short'] = $plan->packet1_options['short'] ?? ''; + $this->options2['short'] = $plan->packet2_options['short'] ?? ''; + $this->options3['short'] = $plan->packet3_options['short'] ?? ''; + + $this->options1['description'] = $plan->packet1_options['description'] ?? ''; + $this->options2['description'] = $plan->packet2_options['description'] ?? ''; + $this->options3['description'] = $plan->packet3_options['description'] ?? ''; } - public function render() + public function render(): View { return view('livewire.plan.accordion'); } - public function toggleAccordionState($optionName) + public function toggleAccordionState(string $optionName): void { $this->accordionState[$optionName] = ! $this->accordionState[$optionName]; @@ -42,12 +54,8 @@ class Accordion extends Component array_map(fn ($key) => $key === $optionName ? $optionName : $this->accordionState[$key] = false, array_keys($this->accordionState)); } - private function unserializeOptions($str) + private function filter_not_empty_items(array $items = []): array { - if (preg_match('/^".*"$/', $str)) { - return json_decode(mb_substr($str, 1, -1), true); - } - - return json_decode($str, true); + return collect($items)->filter(fn ($item) => ! empty($item))->toArray(); } } diff --git a/app/Livewire/Plan/Comment/Create.php b/app/Livewire/Plan/Comment/Create.php index 770b3ef..7bbe742 100644 --- a/app/Livewire/Plan/Comment/Create.php +++ b/app/Livewire/Plan/Comment/Create.php @@ -5,6 +5,7 @@ namespace App\Livewire\Plan\Comment; use App\Models\Plan; use App\Models\PlanComment; 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; + public string|int $grade = 0; - public $isChecked = false; + public bool|string $isChecked = false; - public function render() + public function render(): View { return view('livewire.plan.comment.create'); } - public function toggle() + public function toggle(): void { $this->isChecked = ! $this->isChecked; } - public function save() + public function save(): void { $this->validate([ 'body' => 'required|min:3', diff --git a/app/Livewire/Plan/Comment/Show.php b/app/Livewire/Plan/Comment/Show.php index 21b87c7..17afa1b 100644 --- a/app/Livewire/Plan/Comment/Show.php +++ b/app/Livewire/Plan/Comment/Show.php @@ -3,6 +3,7 @@ namespace App\Livewire\Plan\Comment; use App\Models\Plan; +use Illuminate\View\View; use Livewire\Component; class Show extends Component @@ -11,15 +12,26 @@ class Show extends Component public array $tabpanelState = ['positive' => 'positive', 'negative' => false]; - protected $listeners = ['commentAdded' => '$refresh']; - - public function render() + public function render(): View { return view('livewire.plan.comment.show'); } - public function toggleTabpanelState($tabpanelName) + public function toggleTabpanelState(string $tabpanelName): void { - array_map(fn ($key) => $key === $tabpanelName ? $this->tabpanelState[$tabpanelName] = $tabpanelName : $this->tabpanelState[$key] = false, array_keys($this->tabpanelState)); + collect($this->tabpanelState)->keys()->each( + function ($key) use ($tabpanelName) { + if ($key === $tabpanelName) { + $this->tabpanelState[$tabpanelName] = $tabpanelName; + } else { + $this->tabpanelState[$key] = false; + } + } + ); + } + + protected function getListeners(): array + { + return ['commentAdded' => '$refresh']; } } diff --git a/app/Livewire/Plan/Comment/Upvote.php b/app/Livewire/Plan/Comment/Upvote.php index 4ca0d0c..7a474ce 100644 --- a/app/Livewire/Plan/Comment/Upvote.php +++ b/app/Livewire/Plan/Comment/Upvote.php @@ -3,18 +3,19 @@ namespace App\Livewire\Plan\Comment; use App\Models\PlanComment; +use Illuminate\View\View; use Livewire\Component; class Upvote extends Component { public PlanComment $comment; - public function mount(PlanComment $comment) + public function mount(PlanComment $comment): void { $this->comment = $comment; } - public function render() + public function render(): View { $upvotes = $this->comment->upvotes()->forPlanCommentsUpVote($this->comment)->count(); $downvotes = $this->comment->upvotes()->forPlanCommentsDownVote($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(); diff --git a/app/Livewire/Plan/Create.php b/app/Livewire/Plan/Create.php index 9864e6e..4fd3d68 100644 --- a/app/Livewire/Plan/Create.php +++ b/app/Livewire/Plan/Create.php @@ -3,52 +3,134 @@ namespace App\Livewire\Plan; use App\Models\Plan; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Auth; -use Livewire\Component; /* use Tonysm\RichTextLaravel\Livewire\WithRichTexts; */ +use Illuminate\View\View; +use Livewire\Component; use Livewire\WithFileUploads; class Create extends Component { use WithFileUploads; - public $name = ''; + public string $name = ''; - public $image = null; + public UploadedFile|null $image = null; - public $duration = '7'; + public int|string $duration = 7; - public $state = 'draft'; + public string $state = 'draft'; - public $type = ['fit' => false, 'slim' => false, 'behavior' => false, 'wellness' => false]; + public array $type = ['fit' => false, 'slim' => false, 'behavior' => false, 'wellness' => false]; - public $details = ''; + public string $details = ''; - public $packets_count = 1; + public int $packets_count = 1; - public $packet1_options = []; + public array $packet1_options = []; - public $packet2_options = []; + public array $packet2_options = []; - public $packet3_options = []; + public array $packet3_options = []; - public $packet1_options_input = []; + public array $packet1_options_input = []; - public $packet2_options_input = []; + public array $packet2_options_input = []; - public $packet3_options_input = []; + public array $packet3_options_input = []; - public $input_items_1 = ''; + public string $input_items_1 = ''; - public $input_items_2 = ''; + public string $input_items_2 = ''; - public $input_items_3 = ''; + public string $input_items_3 = ''; - public $isVisibleDuration = false; + public bool $isVisibleDuration = false; - public $isVisibleState = false; + public bool $isVisibleState = false; - protected function rules() + public function render(): View + { + return view('livewire.plan.create'); + } + + public function showListDuration(): void + { + $this->isVisibleDuration = ! $this->isVisibleDuration; + } + + public function showListState(): void + { + $this->isVisibleState = ! $this->isVisibleState; + } + + public function toggleDuration(string $duration): void + { + $this->duration = $duration; + $this->isVisibleDuration = false; + } + + public function toggleState(string $state): void + { + $this->state = $state; + $this->isVisibleState = false; + } + + public function addPacketOption(array $options_type, array $options_type_input): void + { + $this->$options_type['short'] = $this->$options_type_input['short']; + $this->$options_type['price'] = $this->$options_type_input['price']; + $this->$options_type['description'] = $this->$options_type_input['description']; + $this->$options_type['items'][] = $this->input_items_1; + $this->$options_type['items'][] = $this->input_items_2; + $this->$options_type['items'][] = $this->input_items_3; + + // delete empty value in items + $this->$options_type['items'] = array_filter($this->$options_type['items'], fn ($item) => ! empty($item)); + $this->reset('input_items_1'); + $this->reset('input_items_2'); + $this->reset('input_items_3'); + } + + public function publish(): void + { + $this->validate(); + + $plan = new Plan(); + + $plan->name = $this->name; + $plan->image = $this->image->store('plans'); + $plan->duration = $this->duration; + $plan->state = $this->state; + $plan->details = $this->details; + $plan->packets_count = $this->packets_count; + $plan->type = $this->type; + $plan->packet1_options = $this->packet1_options; + $plan->packet2_options = $this->packet2_options; + $plan->packet3_options = $this->packet3_options; + + $plan->saveOrFail(); + + $user = Auth::user(); + $user->author_of_plans()->attach($plan->id); + + $this->redirectRoute('plan.show', $plan); + } + + public function addToDrafts(): void + { + $this->state = 'draft'; + $this->publish(); + } + + public function showPreview(): void + { + $this->state = 'unactive'; + $this->publish(); + } + + protected function rules(): array { $rules = [ 'name' => 'required|min:3', @@ -77,84 +159,4 @@ class Create extends Component return $rules; } - - public function render() - { - return view('livewire.plan.create'); - } - - public function showListDuration() - { - $this->isVisibleDuration = ! $this->isVisibleDuration; - } - - public function showListState() - { - $this->isVisibleState = ! $this->isVisibleState; - } - - public function toggleDuration($duration) - { - $this->duration = $duration; - $this->isVisibleDuration = false; - } - - public function toggleState($state) - { - $this->state = $state; - $this->isVisibleState = false; - } - - public function addPacketOption($options_type, $options_type_input) - { - $this->$options_type['short'] = $this->$options_type_input['short']; - $this->$options_type['price'] = $this->$options_type_input['price']; - $this->$options_type['description'] = $this->$options_type_input['description']; - $this->$options_type['items'][] = $this->input_items_1; - $this->$options_type['items'][] = $this->input_items_2; - $this->$options_type['items'][] = $this->input_items_3; - - // delete empty value in items - $this->$options_type['items'] = array_filter($this->$options_type['items'], fn ($item) => ! empty($item)); - $this->reset('input_items_1'); - $this->reset('input_items_2'); - $this->reset('input_items_3'); - } - - public function publish() - { - $this->validate(); - - $plan = new Plan(); - - $plan->name = $this->name; - $plan->image = $this->image->store('plans', 'public'); - $plan->duration = $this->duration; - $plan->state = $this->state; - $plan->details = $this->details; - $plan->packets_count = $this->packets_count; - $plan->type = $this->type; - $plan->packet1_options = $this->packet1_options; - $plan->packet2_options = $this->packet2_options; - $plan->packet3_options = $this->packet3_options; - - $plan->saveOrFail(); - - $user = Auth::user(); - $user->author_of_plans()->attach($plan->id); - - return redirect()->route('plan.show', $plan->slug); - } - - public function addToDrafts() - { - $this->state = 'draft'; - $this->publish(); - } - - public function showPreview() - { - $this->state = 'unactive'; - $this->publish(); - } } diff --git a/app/Livewire/Plan/Edit.php b/app/Livewire/Plan/Edit.php index 6779057..c8920c1 100644 --- a/app/Livewire/Plan/Edit.php +++ b/app/Livewire/Plan/Edit.php @@ -3,6 +3,8 @@ namespace App\Livewire\Plan; use App\Models\Plan; +use Illuminate\Http\UploadedFile; +use Illuminate\View\View; use Livewire\Component; use Livewire\WithFileUploads; @@ -12,43 +14,43 @@ class Edit extends Component public Plan $plan; - public $name = ''; + public string $name = ''; - public $image = null; + public string|UploadedFile $image = ''; - public $duration = '7'; + public string|int $duration = '7'; - public $state = 'draft'; + public string $state = 'draft'; - public $type = ['fit' => false, 'slim' => false, 'behavior' => false, 'wellness' => false]; + public array $type = ['fit' => false, 'slim' => false, 'behavior' => false, 'wellness' => false]; - public $details = ''; + public string $details = ''; - public $packets_count = 1; + public int $packets_count = 1; - public $packet1_options = []; + public array $packet1_options = []; - public $packet2_options = []; + public array|string $packet2_options = []; - public $packet3_options = []; + public array|string $packet3_options = []; - public $packet1_options_input = []; + public array $packet1_options_input = []; - public $packet2_options_input = []; + public array $packet2_options_input = []; - public $packet3_options_input = []; + public array $packet3_options_input = []; - public $input_items_1 = ''; + public string $input_items_1 = ''; - public $input_items_2 = ''; + public string $input_items_2 = ''; - public $input_items_3 = ''; + public string $input_items_3 = ''; - public $isVisibleDuration = false; + public bool $isVisibleDuration = false; - public $isVisibleState = false; + public bool $isVisibleState = false; - public function mount(Plan $plan) + public function mount(Plan $plan): void { $this->plan = $plan; @@ -71,7 +73,6 @@ class Edit extends Component $this->packet1_options['items'] = $plan->packet1_options['items']; if ($plan->packets_count === 3) { - $this->packet2_options_input['short'] = $plan->packet2_options['short']; $this->packet2_options_input['price'] = $plan->packet2_options['price']; $this->packet2_options_input['description'] = $plan->packet2_options['description']; @@ -97,7 +98,86 @@ class Edit extends Component // commentsCount } - protected function rules() + public function showListDuration(): void + { + $this->isVisibleDuration = ! $this->isVisibleDuration; + } + + public function showListState(): void + { + $this->isVisibleState = ! $this->isVisibleState; + } + + public function toggleDuration(string $duration): void + { + $this->duration = $duration; + $this->isVisibleDuration = false; + } + + public function toggleState(string $state): void + { + $this->state = $state; + $this->isVisibleState = false; + } + + public function addPacketOption(array $options_type, array $options_type_input): void + { + $this->$options_type['short'] = $this->$options_type_input['short']; + $this->$options_type['price'] = $this->$options_type_input['price']; + $this->$options_type['description'] = $this->$options_type_input['description']; + + $this->$options_type['items'][] = $this->input_items_1; + $this->$options_type['items'][] = $this->input_items_2; + $this->$options_type['items'][] = $this->input_items_3; + + // delete empty value in items + $this->$options_type['items'] = array_filter($this->$options_type['items'], fn ($item) => ! empty($item)); + $this->reset('input_items_1'); + $this->reset('input_items_2'); + $this->reset('input_items_3'); + } + + public function publish(): void + { + $this->validate(); + + $this->plan->name = $this->name; + $this->plan->image = ! is_string($this->image) ? $this->image->store('plans') : $this->image; + $this->plan->duration = $this->duration; + $this->plan->state = $this->state; + $this->plan->details = $this->details; + $this->plan->packets_count = $this->packets_count; + $this->plan->type = $this->type; + $this->plan->packet1_options = $this->packet1_options; + $this->plan->packet2_options = $this->packet2_options; + $this->plan->packet3_options = $this->packet3_options; + + $this->plan->update(); + + // $user = Auth::user(); + // $user->author_of_plans()->attach($plan->id); + + $this->redirectRoute('plan.show', $this->plan); + } + + public function addToDrafts(): void + { + $this->state = 'draft'; + $this->publish(); + } + + public function showPreview(): void + { + $this->state = 'unactive'; + $this->publish(); + } + + public function render(): View + { + return view('livewire.plan.edit'); + } + + protected function rules(): array { $rules = [ 'name' => 'required|min:3', @@ -126,83 +206,4 @@ class Edit extends Component return $rules; } - - public function showListDuration() - { - $this->isVisibleDuration = ! $this->isVisibleDuration; - } - - public function showListState() - { - $this->isVisibleState = ! $this->isVisibleState; - } - - public function toggleDuration($duration) - { - $this->duration = $duration; - $this->isVisibleDuration = false; - } - - public function toggleState($state) - { - $this->state = $state; - $this->isVisibleState = false; - } - - public function addPacketOption($options_type, $options_type_input) - { - $this->$options_type['short'] = $this->$options_type_input['short']; - $this->$options_type['price'] = $this->$options_type_input['price']; - $this->$options_type['description'] = $this->$options_type_input['description']; - - $this->$options_type['items'][] = $this->input_items_1; - $this->$options_type['items'][] = $this->input_items_2; - $this->$options_type['items'][] = $this->input_items_3; - - // delete empty value in items - $this->$options_type['items'] = array_filter($this->$options_type['items'], fn ($item) => ! empty($item)); - $this->reset('input_items_1'); - $this->reset('input_items_2'); - $this->reset('input_items_3'); - } - - public function publish() - { - $this->validate(); - - $this->plan->name = $this->name; - $this->plan->image = ! is_string($this->image) ? $this->image->store('plans', 'public') : $this->image; - $this->plan->duration = $this->duration; - $this->plan->state = $this->state; - $this->plan->details = $this->details; - $this->plan->packets_count = $this->packets_count; - $this->plan->type = $this->type; - $this->plan->packet1_options = $this->packet1_options; - $this->plan->packet2_options = $this->packet2_options; - $this->plan->packet3_options = $this->packet3_options; - - $this->plan->update(); - - // $user = Auth::user(); - // $user->author_of_plans()->attach($plan->id); - - return redirect()->route('plan.show', $this->plan->slug); - } - - public function addToDrafts() - { - $this->state = 'draft'; - $this->publish(); - } - - public function showPreview() - { - $this->state = 'unactive'; - $this->publish(); - } - - public function render() - { - return view('livewire.plan.edit'); - } } diff --git a/app/Livewire/Plan/Like/AnnouncementDetails.php b/app/Livewire/Plan/Like/AnnouncementDetails.php new file mode 100755 index 0000000..b5eed28 --- /dev/null +++ b/app/Livewire/Plan/Like/AnnouncementDetails.php @@ -0,0 +1,40 @@ +plan = $plan; + } + + public function render(): View + { + return view('livewire.plan.like.announcement-details'); + } + + #[On('liked-details')] + public function like(): void + { + if ($this->plan->isLiked()) { + $this->plan->removeLike(); + } elseif (auth()->user()) { + $this->plan->likes()->create([ + 'user_id' => auth()->id(), + 'plan_id' => $this->plan->id, + ]); + } else { + return; + } + + $this->dispatch('liked-details')->to('plan.like-count'); + } +} diff --git a/app/Livewire/Plan/Like.php b/app/Livewire/Plan/Like/AnnouncementFooter.php old mode 100644 new mode 100755 similarity index 53% rename from app/Livewire/Plan/Like.php rename to app/Livewire/Plan/Like/AnnouncementFooter.php index c3fe1b8..0cb3efb --- a/app/Livewire/Plan/Like.php +++ b/app/Livewire/Plan/Like/AnnouncementFooter.php @@ -1,24 +1,27 @@ plan = $plan; } - public function render() + public function render(): View { - return view('livewire.plan.like'); + return view('livewire.plan.like.announcement-footer'); } + #[On('liked-footer')] public function like(): void { if ($this->plan->isLiked()) { @@ -28,8 +31,10 @@ class Like extends Component 'user_id' => auth()->id(), 'plan_id' => $this->plan->id, ]); + } else { + return; } - $this->dispatch('liked')->to('plan.like-count'); + $this->dispatch('liked-footer')->to('plan.like-count'); } } diff --git a/app/Livewire/Plan/LikeCount.php b/app/Livewire/Plan/LikeCount.php old mode 100644 new mode 100755 index 2995cb6..d63e4e1 --- a/app/Livewire/Plan/LikeCount.php +++ b/app/Livewire/Plan/LikeCount.php @@ -3,21 +3,23 @@ namespace App\Livewire\Plan; use App\Models\Plan; +use Illuminate\View\View; use Livewire\Component; class LikeCount extends Component { public Plan $plan; - protected $listeners = ['liked' => '$refresh']; - - public function mount(Plan $plan) + public function mount(Plan $plan): void { $this->plan = $plan; } - public function render() + public function render(): View { + $this->dispatch('liked-details'); + $this->dispatch('liked-footer'); + return view( 'livewire.plan.like-count', [ @@ -25,4 +27,9 @@ class LikeCount extends Component ] ); } + + protected function getListeners(): array + { + return ['liked-details' => '$refresh', 'liked-footer' => '$refresh']; + } } diff --git a/app/Livewire/PortionShow.php b/app/Livewire/PortionShow.php index 5753b6a..1cb3110 100644 --- a/app/Livewire/PortionShow.php +++ b/app/Livewire/PortionShow.php @@ -2,11 +2,13 @@ namespace App\Livewire; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class PortionShow extends Component { - public function render() + public function render(): View|ViewFactory { return view('livewire.portion-show'); } diff --git a/app/Livewire/ProductNutritional/Create.php b/app/Livewire/ProductNutritional/Create.php index 7a66d7f..d8af0fb 100644 --- a/app/Livewire/ProductNutritional/Create.php +++ b/app/Livewire/ProductNutritional/Create.php @@ -4,6 +4,9 @@ namespace App\Livewire\ProductNutritional; use App\Models\ProductGroup; use App\Models\ProductNutritionalValue; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Http\UploadedFile; use Livewire\Component; use Livewire\WithFileUploads; @@ -11,66 +14,65 @@ class Create extends Component { use WithFileUploads; - public $name; + public string $name = ''; - public $product_group; + public int|string $product_group; - public $image; + public ?UploadedFile $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|ViewFactory { return view('livewire.product-nutritional.create', ['productGroups' => ProductGroup::all()]); } - public function save() + public function save(): void { $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; - - return redirect()->route('product_nutritional_value.index'); + $this->redirectRoute('product_nutritional_value.index'); } - public function recalulateVals($mass) + public function recalulateVals(int $mass): void { $productKeys = [ ['energy_on_100gr', 'energy_on_portion'], @@ -83,13 +85,13 @@ class Create extends Component foreach ($productKeys as [$key100, $keyPortion]) { if ($this->{$keyPortion}) { - $newVal = (float) ($k * (float) $this->{$keyPortion}); + $newVal = $k * (float) $this->{$keyPortion}; $this->fill([$key100 => $newVal]); } } } - public function recalulatePortionVals($mass) + public function recalulatePortionVals(int $mass): void { $productKeys = [ ['energy_on_100gr', 'energy_on_portion'], @@ -101,27 +103,27 @@ class Create extends Component $k = $mass / 100; foreach ($productKeys as [$key100, $keyPortion]) { if ($this->{$key100}) { - $newVal = (float) ($k * (float) $this->{$key100}); + $newVal = $k * (float) $this->{$key100}; $this->fill([$keyPortion => $newVal]); } } } - 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(); diff --git a/app/Livewire/ProductNutritional/Edit.php b/app/Livewire/ProductNutritional/Edit.php index 9c1df3f..530a099 100644 --- a/app/Livewire/ProductNutritional/Edit.php +++ b/app/Livewire/ProductNutritional/Edit.php @@ -4,6 +4,9 @@ namespace App\Livewire\ProductNutritional; use App\Models\ProductGroup; use App\Models\ProductNutritionalValue; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Http\UploadedFile; use Livewire\Component; use Livewire\WithFileUploads; @@ -11,37 +14,37 @@ 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; @@ -57,17 +60,18 @@ class Edit extends Component $this->proteins_on_portion = $product->proteins_on_portion; $this->fats_on_portion = $product->fats_on_portion; $this->carbohydrates_on_portion = $product->carbohydrates_on_portion; + $this->product = $product; } - public function render() + public function render(): View|ViewFactory { return view('livewire.product-nutritional.edit', ['productGroups' => ProductGroup::all()]); } - public function save() + public function save(): void { 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,23 +79,23 @@ 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(); - return redirect()->route('product_nutritional_value.index'); + $this->redirectRoute('product_nutritional_value.index'); } - public function recalulateVals($mass) + public function recalulateVals(int $mass): void { $productKeys = [ ['energy_on_100gr', 'energy_on_portion'], @@ -104,13 +108,13 @@ class Edit extends Component foreach ($productKeys as [$key100, $keyPortion]) { if ($this->{$keyPortion}) { - $newVal = (float) ($k * (float) $this->{$keyPortion}); + $newVal = $k * (float) $this->{$keyPortion}; $this->fill([$key100 => $newVal]); } } } - public function recalulatePortionVals($mass) + public function recalulatePortionVals(int $mass): void { $productKeys = [ ['energy_on_100gr', 'energy_on_portion'], @@ -122,30 +126,30 @@ class Edit extends Component $k = $mass / 100; foreach ($productKeys as [$key100, $keyPortion]) { if ($this->{$key100}) { - $newVal = (float) ($k * (float) $this->{$key100}); + $newVal = $k * (float) $this->{$key100}; $this->fill([$keyPortion => $newVal]); } } } - 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(): void { $this->product->delete(); - return redirect()->route('product_nutritional_value.index'); + $this->redirectRoute('product_nutritional_value.index'); } } diff --git a/app/Livewire/ProductNutritional/Index.php b/app/Livewire/ProductNutritional/Index.php index c2ce366..c69676b 100644 --- a/app/Livewire/ProductNutritional/Index.php +++ b/app/Livewire/ProductNutritional/Index.php @@ -3,11 +3,13 @@ namespace App\Livewire\ProductNutritional; use App\Models\ProductNutritionalValue; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; class Index extends Component { - public function render() + public function render(): View|ViewFactory { return view('livewire.product-nutritional.index', ['products' => ProductNutritionalValue::all()]); } diff --git a/app/Livewire/Profile/CircumferenceChart.php b/app/Livewire/Profile/CircumferenceChart.php index 4ac2f1b..e026dc0 100644 --- a/app/Livewire/Profile/CircumferenceChart.php +++ b/app/Livewire/Profile/CircumferenceChart.php @@ -4,21 +4,21 @@ namespace App\Livewire\Profile; use App\Models\User; use Asantibanez\LivewireCharts\Models\LineChartModel; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\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|ViewFactory { $lastOneMisure = $this ->user ->circumference_measures() - ->get() - ->last(); + ->latest() + ->first(); $lastFourMisures = $this ->user @@ -35,7 +35,7 @@ class CircumferenceChart extends Component ->setColors(['#b2df8a', '#1f78b4', '#e3a6a6']); $lastFourMisures->each( - function ($item, $key) use ($lineChartModel) { + function ($item) use ($lineChartModel) { $createdAt = \Carbon\Carbon::parse($item['created_at'])->format('d.m.y'); $lineChartModel->addSeriesPoint(__('chest'), $createdAt, $item['chest_circumference']); $lineChartModel->addSeriesPoint(__('waist'), $createdAt, $item['waist_circumference']); @@ -52,4 +52,9 @@ class CircumferenceChart extends Component ] ); } + + protected function getListeners(): array + { + return ['circumference-chart-updated' => '$refresh']; + } } diff --git a/app/Livewire/Profile/DescriptionForm.php b/app/Livewire/Profile/DescriptionForm.php index c33962a..06f74f6 100644 --- a/app/Livewire/Profile/DescriptionForm.php +++ b/app/Livewire/Profile/DescriptionForm.php @@ -2,22 +2,25 @@ namespace App\Livewire\Profile; +use App\Models\User; use App\Models\UserDetailz; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\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 +28,12 @@ class DescriptionForm extends Component $userDetailz->save(); } - public function render() + public function render(): View|ViewFactory { return view('livewire.profile.description-form'); } - private function initDetailzIfNeeded() + private function initDetailzIfNeeded(): void { $curUserDetailez = UserDetailz::firstOrNew( ['user_id' => $this->user->id], @@ -44,7 +47,7 @@ class DescriptionForm extends Component ] ); - if (is_null($curUserDetailez->id)) { + if (! isset($curUserDetailez->id)) { $curUserDetailez->save(); } } diff --git a/app/Livewire/Profile/EditDetailzForm.php b/app/Livewire/Profile/EditDetailzForm.php index 5cdf7ec..04bcf7e 100644 --- a/app/Livewire/Profile/EditDetailzForm.php +++ b/app/Livewire/Profile/EditDetailzForm.php @@ -5,6 +5,8 @@ namespace App\Livewire\Profile; use App\Livewire\Forms\ProfileEditDetailzForm; use App\Models\User; use App\Models\UserDetailz; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; use Livewire\Component; @@ -17,21 +19,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 +56,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|ViewFactory { return view('livewire.profile.edit-detailz-form'); } diff --git a/app/Livewire/Profile/PhotoForm.php b/app/Livewire/Profile/PhotoForm.php index d1297cb..924fc80 100644 --- a/app/Livewire/Profile/PhotoForm.php +++ b/app/Livewire/Profile/PhotoForm.php @@ -2,40 +2,30 @@ namespace App\Livewire\Profile; +use App\Models\User; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Laravel\Fortify\Contracts\UpdatesUserProfileInformation; use Livewire\Component; +use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; use Livewire\WithFileUploads; 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 +41,7 @@ class PhotoForm extends Component $this->isOnline = now()->unix() - $lastActivity < 150; } - /** - * Update the user's profile information. - * - * @return void - */ - public function updateProfileInformation(UpdatesUserProfileInformation $updater) + public function updateProfileInformation(UpdatesUserProfileInformation $updater): void { $this->resetErrorBag(); @@ -70,36 +55,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|ViewFactory { return view('livewire.profile.photo-form'); } diff --git a/app/Livewire/Profile/ShowDetailz.php b/app/Livewire/Profile/ShowDetailz.php index d31c4a3..0824f8f 100644 --- a/app/Livewire/Profile/ShowDetailz.php +++ b/app/Livewire/Profile/ShowDetailz.php @@ -2,43 +2,48 @@ namespace App\Livewire\Profile; +use App\Models\User; +use App\Models\UserDetailz; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Component; use Masmerise\Toaster\Toaster; class ShowDetailz extends Component { - 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|ViewFactory { return view('livewire.profile.show-detailz'); } - public function editAction() + public function editAction(): void { - return redirect()->route('user_detailz.edit', $this->userDetailz->id); + //return redirect()->route('user_detailz.edit', $this->userDetailz->id); + $this->redirectRoute('user_detailz.edit', $this->userDetailz->id); } - public function updated($name, $value): void + public function updated(string $name, mixed $value): void { if ($name === 'is_bedtime_fillable') { $this->user->detailz->update(['is_bedtime_fillable' => $value]); diff --git a/app/Livewire/Profile/WeightChart.php b/app/Livewire/Profile/WeightChart.php index 0cb20e5..27525f7 100644 --- a/app/Livewire/Profile/WeightChart.php +++ b/app/Livewire/Profile/WeightChart.php @@ -4,15 +4,15 @@ namespace App\Livewire\Profile; use App\Models\User; use Asantibanez\LivewireCharts\Models\AreaChartModel; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\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|ViewFactory { $areaChartModel = (new AreaChartModel()) @@ -41,4 +41,9 @@ class WeightChart extends Component ] ); } + + protected function getListeners(): array + { + return ['weight-chart-updated' => '$refresh']; + } } diff --git a/app/Livewire/Recipe/Comment/Create.php b/app/Livewire/Recipe/Comment/Create.php index e0a0aff..40bc80f 100644 --- a/app/Livewire/Recipe/Comment/Create.php +++ b/app/Livewire/Recipe/Comment/Create.php @@ -5,6 +5,7 @@ namespace App\Livewire\Recipe\Comment; use App\Models\Recipe; use App\Models\RecipeComment; 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 = false; + public bool|string $isChecked = false; - public function render() + public function render(): View { return view('livewire.recipe.comment.create'); } - public function toggle() + public function toggle(): void { - $this->isChecked = !$this->isChecked; + $this->isChecked = ! $this->isChecked; } - public function save() + public function save(): void { $this->validate([ 'body' => 'required|min:3', diff --git a/app/Livewire/Recipe/Comment/Show.php b/app/Livewire/Recipe/Comment/Show.php index ca2278f..f731ccb 100644 --- a/app/Livewire/Recipe/Comment/Show.php +++ b/app/Livewire/Recipe/Comment/Show.php @@ -3,6 +3,7 @@ namespace App\Livewire\Recipe\Comment; use App\Models\Recipe; +use Illuminate\View\View; use Livewire\Component; class Show extends Component @@ -11,17 +12,28 @@ class Show extends Component public array $tabpanelState = ['positive' => 'positive', 'negative' => false]; - protected $listeners = ['commentAdded' => '$refresh']; + // protected $listeners = ['commentAdded' => '$refresh']; - public function render() + public function render(): View { return view('livewire.recipe.comment.show'); } - public function toggleTabpanelState($tabpanelName) + public function toggleTabpanelState(string $tabpanelName): void { - collect($this->tabpanelState)->keys()->map(fn($key) => $key === $tabpanelName - ? $this->tabpanelState[$tabpanelName] = $tabpanelName - : $this->tabpanelState[$key] = false, array_keys($this->tabpanelState)); + collect($this->tabpanelState)->keys()->each( + function ($key) use ($tabpanelName) { + if ($key === $tabpanelName) { + $this->tabpanelState[$tabpanelName] = $tabpanelName; + } else { + $this->tabpanelState[$key] = false; + } + } + ); + } + + protected function getListeners(): array + { + return ['commentAdded' => '$refresh']; } } diff --git a/app/Livewire/Recipe/Comment/Upvote.php b/app/Livewire/Recipe/Comment/Upvote.php index 8e7ec64..b889295 100644 --- a/app/Livewire/Recipe/Comment/Upvote.php +++ b/app/Livewire/Recipe/Comment/Upvote.php @@ -3,18 +3,19 @@ namespace App\Livewire\Recipe\Comment; use App\Models\RecipeComment; +use Illuminate\View\View; use Livewire\Component; class Upvote extends Component { public RecipeComment $comment; - public function mount(RecipeComment $comment) + public function mount(RecipeComment $comment): void { $this->comment = $comment; } - public function render() + public function render(): View { $upvotes = $this->comment->upvotes()->forRecipeCommentsUpVote($this->comment)->count(); $downvotes = $this->comment->upvotes()->forRecipeCommentsDownVote($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(); diff --git a/app/Livewire/Recipe/Create.php b/app/Livewire/Recipe/Create.php index a1d1c51..447551e 100644 --- a/app/Livewire/Recipe/Create.php +++ b/app/Livewire/Recipe/Create.php @@ -4,7 +4,10 @@ namespace App\Livewire\Recipe; use App\Models\Recipe; use App\Models\Tag; +use Illuminate\Http\UploadedFile; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; +use Illuminate\View\View; use Livewire\Attributes\On; use Livewire\Component; use Livewire\WithFileUploads; @@ -13,47 +16,46 @@ class Create extends Component { use WithFileUploads; - public $image; + // public TemporaryUploadedFile $image; + public UploadedFile|null $image = null; - public $state = 'active'; + public string $state = 'active'; - public $state_ingredient = 'active'; + public string $state_ingredient = 'active'; - public $state_article = 'active'; + public string $state_article = 'active'; - public $tags = []; + public array $tags = []; - public $title; + public string $title; - public $type = 'other'; + public string $type = 'other'; - public $video_url = ''; + public string $video_url = ''; - public $cooking_time = '10'; + public int|string $cooking_time = '10'; - public $description = ''; + public string $description = ''; - public $steps = [['image' => '', 'description' => '']]; + public Collection|array $steps = [['image' => '', 'description' => '']]; - public $ingredients = []; + public Collection|array $ingredients = []; - public $ingredients_name = ''; + public string $ingredients_name = ''; - public $ingredients_portion = ''; - - public $ingredients_unit = 'gr'; - - public $state_row = ['ingredient' => 'true', 'article' => 'false']; - - protected $listeners = ['stepRemoved' => '$refresh']; + public string $ingredients_portion = ''; + public string $ingredients_unit = 'gr'; + public array $state_row = ['ingredient' => 'true', 'article' => 'false']; public function toggleStateRow(string $currentRow): void { - collect($this->state_row)->keys()->map(fn($key) => $key === $currentRow + collect($this->state_row)->keys()->map( + fn ($key) => $key === $currentRow ? $this->state_row[$currentRow] = 'true' - : $this->state_row[$key] = 'false'); + : $this->state_row[$key] = 'false' + ); } public function addIngredient(): void @@ -66,19 +68,19 @@ class Create extends Component $this->reset('ingredients_name', 'ingredients_portion', 'ingredients_unit'); } - public function removeIngredient($i) + public function removeIngredient(int $i): void { $newIngredients = collect($this->ingredients) ->forget($i); $this->ingredients = $newIngredients->toArray(); } - public function addStep() + public function addStep(): void { $this->steps[] = ['image' => '', 'description' => '']; } - public function removeStep($i) + public function removeStep(int $i): void { $searchKey = $i - 1; $newSteps = array_filter( @@ -94,27 +96,27 @@ class Create extends Component } #[On('parentComponentTagAdded')] - public function parentComponentTagAdded(Tag $tag) + public function parentComponentTagAdded(Tag $tag): void { $tagIndex = $tag->id; $this->tags[$tagIndex] = $tag; } #[On('parentComponentTagRemoved')] - public function parentComponentTagRemoved($tag) + public function parentComponentTagRemoved(Tag $tag): void { $this->tags = collect($this->tags) - ->filter(fn($curTag) => $curTag['name'] !== $tag) + ->filter(fn ($curTag) => $curTag['name'] !== $tag) ->all(); } - public function draft() + public function draft(): void { $this->state = 'archived'; $this->publish(); } - public function preview() + public function preview(): void { $this->validate(); @@ -122,7 +124,43 @@ class Create extends Component $this->publish(); } - protected function rules() + public function publish(): void + { + $this->validate(); + + $recipe = new Recipe(); + // $recipe->image = $this->image->store('recipe', 'public'); + $recipe->image = $this->image->store('recipe'); + $recipe->state = $this->state; + $recipe->type = $this->type; + $recipe->cooking_time = $this->cooking_time; + $recipe->title = $this->title; + $recipe->description = $this->description; + $recipe->video_url = $this->video_url; + $recipe->steps = $this->transformSteps($this->steps); + $recipe->ingredients = $this->ingredients; + $recipe->save(); + + $tagsIds = collect($this->tags)->map(fn ($curTag) => $curTag['id']); + $recipe->tags()->attach($tagsIds); + + $user = Auth::user(); + $user->author_of_recipe()->attach($recipe->id); + + $this->redirectRoute('recipe.show', $recipe); + } + + public function render(): View + { + return view('livewire.recipe.create'); + } + + protected function getListeners(): array + { + return ['stepRemoved' => '$refresh']; + } + + protected function rules(): array { return [ 'image' => 'required|image|max:2048', @@ -134,40 +172,14 @@ class Create extends Component ]; } - public function publish() - { - - $this->validate(); - - $recipe = new Recipe(); - $recipe->image = $this->image->store('recipe', 'public'); - $recipe->state = $this->state; - $recipe->type = $this->type; - $recipe->cooking_time = $this->cooking_time; - $recipe->title = $this->title; - $recipe->description = $this->description; - $recipe->video_url = $this->video_url; - $recipe->steps = $this->transformSteps($this->steps); - $recipe->ingredients = $this->ingredients; - $recipe->save(); - - $tagsIds = collect($this->tags)->map(fn($curTag) => $curTag['id']); - $recipe->tags()->attach($tagsIds); - - $user = Auth::user(); - $user->author_of_recipe()->attach($recipe->id); - - return redirect()->route('recipe.show', $recipe->id); - } - - private function transformSteps($steps) + private function transformSteps(array $steps): array { return collect($steps)->map( function ($step) { if (gettype($step['image']) === 'string') { $data['image'] = $step['image']; } else { - $data['image'] = !is_null($step['image']) ? $step['image']->store('steps', 'public') : ''; + $data['image'] = ! is_null($step['image']) ? $step['image']->store('steps', 'public') : ''; } $data['description'] = $step['description']; @@ -176,12 +188,4 @@ class Create extends Component } )->toArray(); } - - - public function render() - { - return view('livewire.recipe.create'); - } - - } diff --git a/app/Livewire/Recipe/Edit.php b/app/Livewire/Recipe/Edit.php index 928b244..fd7545d 100644 --- a/app/Livewire/Recipe/Edit.php +++ b/app/Livewire/Recipe/Edit.php @@ -4,6 +4,9 @@ namespace App\Livewire\Recipe; use App\Models\Recipe; use App\Models\Tag; +use Illuminate\Database\Eloquent\Casts\AsCollection; +use Illuminate\Support\Collection; +use Illuminate\View\View; use Livewire\Component; use Livewire\WithFileUploads; @@ -13,43 +16,40 @@ class Edit extends Component public Recipe $recipe; - public $image; + public string $image; - public $state = 'active'; + public string $state = 'active'; - public $state_ingredient = 'active'; + public string $state_ingredient = 'active'; - public $state_article = 'active'; + public string $state_article = 'active'; - public $type = 'other'; + public string $type = 'other'; - public $tags; + public Collection $tags; - public $title; + public string $title; - public $video_url; + public string $video_url; - public $cooking_time = '10'; + public string|int $cooking_time = '10'; - public $description = ''; + public string $description = ''; - public $steps = [['image' => '', 'description' => '']]; + public AsCollection|array|Collection $steps = [['image' => '', 'description' => '']]; - public $ingredients = [['name' => '', 'portion' => '']]; + public AsCollection|array|Collection $ingredients = [['name' => '', 'portion' => '']]; - public $ingredients_name = ''; + public string $ingredients_name = ''; - public $ingredients_portion = ''; + public string $ingredients_portion = ''; - public $ingredients_unit = 'gr'; + public string $ingredients_unit = 'gr'; - public $state_row = ['ingredient' => 'true', 'article' => 'false']; + public array $state_row = ['ingredient' => 'true', 'article' => 'false']; - protected $listeners = ['stepRemoved' => '$refresh', 'parentComponentTagAdded', 'parentComponentTagRemoved']; - - public function mount(Recipe $recipe) + public function mount(Recipe $recipe): void { - $this->name = $recipe->name; $this->image = $recipe->image; $this->state = $recipe->state; $this->type = $recipe->type; @@ -64,12 +64,12 @@ class Edit extends Component public function toggleStateRow(string $currentRow): void { - collect($this->state_row)->keys()->map(fn($key) => $key === $currentRow + collect($this->state_row)->keys()->map(fn ($key) => $key === $currentRow ? $this->state_row[$currentRow] = 'true' : $this->state_row[$key] = 'false'); } - public function addIngredient() + public function addIngredient(): void { $this->ingredients[] = [ 'name' => $this->ingredients_name, @@ -79,19 +79,19 @@ class Edit extends Component $this->reset('ingredients_name', 'ingredients_portion', 'ingredients_unit'); } - public function removeIngredient($i) + public function removeIngredient(int $i): void { $newIngredients = collect($this->ingredients) ->forget($i); $this->ingredients = $newIngredients->toArray(); } - public function addStep() + public function addStep(): void { $this->steps[] = ['image' => '', 'description' => '']; } - public function removeStep($i) + public function removeStep(int $i): void { if (is_array($this->steps)) { $steps = $this->steps; @@ -108,52 +108,40 @@ class Edit extends Component ); $this->steps = array_values($newSteps); + $this->dispatch('stepRemoved')->self(); } - public function parentComponentTagAdded(Tag $tag) + public function parentComponentTagAdded(Tag $tag): void { $this->recipe->tags()->attach($tag['id']); } - public function parentComponentTagRemoved($tag) + public function parentComponentTagRemoved(Tag $tag): void { $selectedTags = Tag::where('name', $tag)->pluck('id'); $this->recipe->tags()->detach($selectedTags); } - protected function rules() - { - return [ - 'image' => 'filled', - 'state' => 'required|in:active,archived', - 'description' => 'required|min:3', - 'type' => 'required|min:3', - 'video_url' => 'nullable|url|max:2048', - 'cooking_time' => 'nullable|numeric', - ]; - } - - - public function draft() + public function draft(): void { $this->state = 'archived'; $this->publish(); } - public function preview() + public function preview(): void { $this->state = 'archived'; $this->publish(); } - public function publish() + public function publish(): void { $this->validate(); $recipe = $this->recipe; if (! is_string($this->image)) { - $recipe->image = $this->image->store('recipe', 'public'); + $recipe->image = $this->image->store('recipe'); } $recipe->state = $this->state; @@ -167,10 +155,34 @@ class Edit extends Component $recipe->save(); - return redirect()->route('recipe.show', $recipe->id); + $this->redirectRoute('recipe.show', $recipe); } - private function transformSteps($steps) + public function render(): View + { + return view('livewire.recipe.edit'); + } + + // protected $listeners = ['stepRemoved' => '$refresh', 'parentComponentTagAdded', 'parentComponentTagRemoved']; + + protected function getListeners(): array + { + return ['stepRemoved' => '$refresh', 'parentComponentTagAdded', 'parentComponentTagRemoved']; + } + + protected function rules(): array + { + return [ + 'image' => 'filled', + 'state' => 'required|in:active,archived', + 'description' => 'required|min:3', + 'type' => 'required|min:3', + 'video_url' => 'nullable|url|max:2048', + 'cooking_time' => 'nullable|numeric', + ]; + } + + private function transformSteps(Collection $steps): array { return collect($steps)-> map(function ($step) { @@ -184,11 +196,4 @@ class Edit extends Component return $data; })->toArray(); } - - - public function render() - { - return view('livewire.recipe.edit'); - } - } diff --git a/app/Livewire/Recipe/Like.php b/app/Livewire/Recipe/Like.php index 871d267..b8c2362 100644 --- a/app/Livewire/Recipe/Like.php +++ b/app/Livewire/Recipe/Like.php @@ -3,20 +3,21 @@ namespace App\Livewire\Recipe; use App\Models\Recipe; +use Illuminate\View\View; use Livewire\Component; class Like extends Component { public Recipe $recipe; - public $isIconOnly = false; + public bool $isIconOnly = false; - public function mount(Recipe $recipe) + public function mount(Recipe $recipe): void { $this->recipe = $recipe; } - public function render() + public function render(): View { return view('livewire.recipe.like'); } diff --git a/app/Livewire/Recipe/LikeCount.php b/app/Livewire/Recipe/LikeCount.php index 313b461..e24df23 100644 --- a/app/Livewire/Recipe/LikeCount.php +++ b/app/Livewire/Recipe/LikeCount.php @@ -3,24 +3,28 @@ namespace App\Livewire\Recipe; use App\Models\Recipe; +use Illuminate\View\View; use Livewire\Component; class LikeCount extends Component { public Recipe $recipe; - protected $listeners = ['liked' => '$refresh']; - - public function mount(Recipe $recipe) + public function mount(Recipe $recipe): void { $this->recipe = $recipe; } - public function render() + public function render(): View { return view( 'livewire.recipe.like-count', ['count' => $this->recipe->likes_count] ); } + + protected function getListeners(): array + { + return ['liked' => '$refresh']; + } } diff --git a/app/Livewire/Recipe/ListView.php b/app/Livewire/Recipe/ListView.php index 3a33966..3790be5 100644 --- a/app/Livewire/Recipe/ListView.php +++ b/app/Livewire/Recipe/ListView.php @@ -6,6 +6,7 @@ use App\Models\Recipe; use App\Models\Tag; use App\Models\User; use Illuminate\Support\Str; +use Illuminate\View\View; use Livewire\Component; use Livewire\WithPagination; @@ -13,22 +14,22 @@ class ListView extends Component { use WithPagination; - public $search = ''; + public string $search = ''; - public $typeFilter = 'all'; + public string $typeFilter = 'all'; - public $tag = ''; + public string $tag = ''; - public $author; + public User|null $author = null; - protected $queryString = [ + protected array $queryString = [ 'search' => ['except' => ''], 'typeFilter' => ['except' => 'all'], 'tag' => ['except' => ''], 'author' => ['except' => ''], ]; - public function render() + public function render(): View { if ($this->author) { $author = $this->author; @@ -60,7 +61,7 @@ class ListView extends Component ); } - private function getTagsCollection() + private function getTagsCollection(): array { return Recipe::all()->map( fn ($r) => [ diff --git a/app/Livewire/Registration/Step1.php b/app/Livewire/Registration/Step1.php index f530e27..8d6893f 100644 --- a/app/Livewire/Registration/Step1.php +++ b/app/Livewire/Registration/Step1.php @@ -5,87 +5,87 @@ namespace App\Livewire\Registration; use App\Actions\Fortify\CreateNewUser; use App\Rules\MinWords; use Illuminate\Auth\Events\Registered; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; use Illuminate\Validation\Rule; use Illuminate\Validation\Rules\Password; -// use Laravel\Fortify\Contracts\RegisterResponse; -// use Illuminate\Contracts\Auth\StatefulGuard; -// use App\Models\User; -// use App\Models\UserDetailz; use 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|ViewFactory { - return view('livewire.registration.'.$this->step, ['step' => $this->step]) - ->extends('layouts.register'); + 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,8 +106,14 @@ class Step1 extends Component ); } - public function skipStep() + public function skipStep(): RedirectResponse|Redirector { + $validatedData = $this->getValidateData($this->step); + $registrationdata = session()->get('registrationdata', []); + $mergetdRegistrationData = array_merge($validatedData, $registrationdata); + + session()->put('registrationdata', $mergetdRegistrationData); + return redirect() ->route( 'register.step1', @@ -117,9 +123,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( @@ -130,7 +136,7 @@ class Step1 extends Component ); } - public function finishRegistretion() + public function finishRegistretion(): RedirectResponse|Redirector { $validatedData = Validator::make( $this->getValidateData($this->step), @@ -151,7 +157,7 @@ class Step1 extends Component return redirect()->route('profile.show', $user->id); } - private function getValidateRules($key) + private function getValidateRules(string $key): array { $rules = [ 'step1' => [ @@ -193,7 +199,7 @@ class Step1 extends Component return $rules[$key]; } - private function getValidateData($key) + private function getValidateData(string $key): array { $data = [ 'step1' => [ @@ -236,13 +242,8 @@ class Step1 extends Component return $data[$key]; } - private function getNextStep() + private function getNextStep(): string { - return 'step'.(int) Str::replaceFirst('step', '', $this->step) + 1; - } - - private function getValidateMessages() - { - return ['required' => 'The :attribute field is required']; + return 'step'.((int) Str::replaceFirst('step', '', $this->step) + 1); } } diff --git a/app/Livewire/TagsComponent.php b/app/Livewire/TagsComponent.php index a56fe23..c8d7748 100644 --- a/app/Livewire/TagsComponent.php +++ b/app/Livewire/TagsComponent.php @@ -3,22 +3,27 @@ namespace App\Livewire; // use App\Models\BlogPost; +use App\Models\BlogPost; +use App\Models\Recipe; use App\Models\Tag; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Livewire\Attributes\On; use Livewire\Component; class TagsComponent extends Component { - public $tags; + public string $tags; - public $parentComponent = null; + 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 +49,7 @@ class TagsComponent extends Component $this->dispatch('parentComponentTagRemoved', tag: $tag); } - public function render() + public function render(): View|ViewFactory { return view('livewire.tags-component'); } diff --git a/app/Livewire/User/AddCircumference.php b/app/Livewire/User/AddCircumference.php index 4101b56..58dbf63 100644 --- a/app/Livewire/User/AddCircumference.php +++ b/app/Livewire/User/AddCircumference.php @@ -6,6 +6,8 @@ namespace App\Livewire\User; use App\Models\CircumferenceMeasure; use App\Models\User; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Illuminate\Support\Facades\Auth; use LivewireUI\Modal\ModalComponent; @@ -13,23 +15,23 @@ 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|ViewFactory { return view('livewire.user.add-circumference'); } - public function add() + public function add(): void { $newMeasure = CircumferenceMeasure::create([ 'user_id' => $this->user->id, diff --git a/app/Livewire/User/AddWeight.php b/app/Livewire/User/AddWeight.php index ef4043d..ac5356f 100644 --- a/app/Livewire/User/AddWeight.php +++ b/app/Livewire/User/AddWeight.php @@ -4,6 +4,8 @@ namespace App\Livewire\User; use App\Models\User; use App\Models\WeightMeasure; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Illuminate\Support\Facades\Auth; use LivewireUI\Modal\ModalComponent; @@ -11,19 +13,19 @@ 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|ViewFactory { return view('livewire.user.add-weight'); } - public function add() + public function add(): void { $newMeasure = WeightMeasure::create([ 'user_id' => $this->user->id, diff --git a/app/Messages/ChatMessage.php b/app/Messages/ChatMessage.php new file mode 100644 index 0000000..b0177ec --- /dev/null +++ b/app/Messages/ChatMessage.php @@ -0,0 +1,55 @@ +id = $id; + $this->payload = $payload; + } + + public function someRandomFillFunction(): void + { + $users1 = User::all()->pluck('id'); + $users2 = User::all()->pluck('id'); + $faker = FakerFactory::create(); + + $users1->each( + function ($user1) use ($faker, $users2) { + $users2->each( + function ($user2) use ($faker, $user1) { + if ($user1 === $user2) { + return; + } + $data1 = [ + 'from_user_id' => $user2, + 'to_user_id' => $user1, + 'data' => $faker->text(), + ]; + + $data2 = [ + 'from_user_id' => $user1, + 'to_user_id' => $user2, + 'data' => $faker->text(), + ]; + + $newMessage = (new Chat())->forceFill($data1); + $newMessage->save(); + $newMessage = (new Chat())->forceFill($data2); + $newMessage->save(); + } + ); + } + ); + } +} diff --git a/app/Models/BlogPost.php b/app/Models/BlogPost.php index 6e20721..c79a4be 100644 --- a/app/Models/BlogPost.php +++ b/app/Models/BlogPost.php @@ -4,27 +4,76 @@ namespace App\Models; use CyrildeWit\EloquentViewable\Contracts\Viewable; use CyrildeWit\EloquentViewable\InteractsWithViews; -/* use Illuminate\Database\Eloquent\Builder; */ +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; -/* use Illuminate\Database\Eloquent\Casts\Attribute; */ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasOneThrough; +use Illuminate\Database\Eloquent\Relations\MorphToMany; +use Illuminate\Support\Str; +/** + * App\Models\BlogPost + * + * @property int $id + * @property string $state active/archived + * @property string $image public path to image + * @property string $description + * @property string $youtube_url + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * @property string $title + * + * @property-read \App\Models\User $author + * @property-read \Illuminate\Database\Eloquent\Collection $comments + * @property-read int|null $comments_count + * @property-read \Illuminate\Database\Eloquent\Collection $likes + * @property-read int|null $likes_count + * @property-read \Illuminate\Database\Eloquent\Collection $tags + * @property-read int|null $tags_count + * @property-read \Illuminate\Database\Eloquent\Collection $views + * @property-read int|null $views_count + * + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost containsTag($tagString) + * @method static \Database\Factories\BlogPostFactory factory($count = null, $state = []) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost noEagerLoads() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost orderByUniqueViews(string $direction = 'desc', $period = null, ?string $collection = null, string $as = 'unique_views_count') + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost orderByViews(string $direction = 'desc', ?\CyrildeWit\EloquentViewable\Support\Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count') + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost query() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost whereDescription($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost whereImage($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost whereState($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost whereTitle($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost whereYoutubeUrl($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPost withViewsCount(?\CyrildeWit\EloquentViewable\Support\Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count') + * + * @mixin \Eloquent + */ class BlogPost extends Model implements Viewable { use HasFactory, InteractsWithViews; - protected $withCount = [ - 'likes', - 'comments', - ]; + // protected array $withCount = [ + // 'likes', + // 'comments', + // ]; - public function tags() + public static function getWithLikesAndCommentsCount(): Builder + { + return self::withCount(['likes', 'comments']); + } + + public function tags(): MorphToMany { return $this->morphToMany(Tag::class, 'taggable'); } - public function author() + public function author(): HasOneThrough { return $this ->hasOneThrough(User::class, BlogPostAuthor::class, 'blog_post_id', 'id', 'id', 'user_id') @@ -37,7 +86,7 @@ class BlogPost extends Model implements Viewable ); } - public function comments() + public function comments(): HasMany { return $this->hasMany(BlogPostComment::class); } @@ -47,7 +96,7 @@ class BlogPost extends Model implements Viewable return $this->hasMany(BlogPostLike::class); } - public function isLiked(): bool + public function isLiked(): bool|int { $curUser = auth()->user(); if ($curUser) { @@ -67,12 +116,12 @@ class BlogPost extends Model implements Viewable return false; } - public function scopeNoEagerLoads($query) + public function scopeNoEagerLoads(Builder $query): Builder { return $query->setEagerLoads([]); } - public function scopeContainsTag($query, $tagString): Builder + public function scopeContainsTag(Builder $query, string $tagString): MorphToMany { $tagId = Str::of($tagString)->split('/-/')->first(); diff --git a/app/Models/BlogPostAuthor.php b/app/Models/BlogPostAuthor.php index d7f587b..2ace15c 100644 --- a/app/Models/BlogPostAuthor.php +++ b/app/Models/BlogPostAuthor.php @@ -8,6 +8,26 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; /* use Illuminate\Database\Eloquent\Casts\Attribute; */ use Illuminate\Database\Eloquent\Model; +/** + * App\Models\BlogPostAuthor + * + * @property int $user_id + * @property int $blog_post_id + * + * @property-read \Illuminate\Database\Eloquent\Collection $views + * @property-read int|null $views_count + * + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostAuthor newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostAuthor newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostAuthor orderByUniqueViews(string $direction = 'desc', $period = null, ?string $collection = null, string $as = 'unique_views_count') + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostAuthor orderByViews(string $direction = 'desc', ?\CyrildeWit\EloquentViewable\Support\Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count') + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostAuthor query() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostAuthor whereBlogPostId($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostAuthor whereUserId($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostAuthor withViewsCount(?\CyrildeWit\EloquentViewable\Support\Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count') + * + * @mixin \Eloquent + */ class BlogPostAuthor extends Model { use HasFactory, InteractsWithViews; diff --git a/app/Models/BlogPostComment.php b/app/Models/BlogPostComment.php index e7deb11..d14a6ef 100644 --- a/app/Models/BlogPostComment.php +++ b/app/Models/BlogPostComment.php @@ -4,18 +4,48 @@ 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; +/** + * App\Models\BlogPostComment + * + * @property int $id + * @property int $user_id + * @property int $blog_post_id + * @property int $grade + * @property string|null $body + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\User|null $author + * @property-read \App\Models\BlogPost|null $blog_post + * @property-read \Illuminate\Database\Eloquent\Collection $upvotes + * @property-read int|null $upvotes_count + * + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostComment newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostComment newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostComment query() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostComment whereBlogPostId($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostComment whereBody($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostComment whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostComment whereGrade($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostComment whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostComment whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostComment whereUserId($value) + * + * @mixin \Eloquent + */ class BlogPostComment extends Model { use HasFactory; - public function author() + public function author(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } - public function blog_post() + public function blog_post(): BelongsTo { return $this->belongsTo(BlogPost::class, 'blog_post_id'); } @@ -25,7 +55,7 @@ class BlogPostComment extends Model return $this->hasMany(BlogPostCommentUpvote::class, 'blog_post_comment_id'); } - public function isUpVoted(): bool + public function isUpVoted(): bool|int { $curUser = auth()->user(); if ($curUser) { @@ -38,7 +68,7 @@ class BlogPostComment extends Model return false; } - public function isDownVoted(): bool + public function isDownVoted(): bool|int { $curUser = auth()->user(); if ($curUser) { diff --git a/app/Models/BlogPostCommentUpvote.php b/app/Models/BlogPostCommentUpvote.php index 6f4dd01..07cf998 100644 --- a/app/Models/BlogPostCommentUpvote.php +++ b/app/Models/BlogPostCommentUpvote.php @@ -2,35 +2,67 @@ 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\BlogPostCommentUpvote + * + * @property int $id + * @property int $blog_post_comment_id + * @property int $user_id + * @property string $type + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\User|null $author + * @property-read \App\Models\BlogPostComment|null $blog_post_comment + * + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostCommentUpvote forBlogPostCommentsDownVote(\App\Models\BlogPostComment $comment) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostCommentUpvote forBlogPostCommentsUpVote(\App\Models\BlogPostComment $comment) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostCommentUpvote newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostCommentUpvote newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostCommentUpvote query() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostCommentUpvote whereBlogPostCommentId($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostCommentUpvote whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostCommentUpvote whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostCommentUpvote whereType($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostCommentUpvote whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostCommentUpvote whereUserId($value) + * + * @mixin \Eloquent + */ class BlogPostCommentUpvote extends Model { use HasFactory; + /** + * @var array + */ protected $fillable = [ 'user_id', 'blog_post_comment_id', 'type', ]; - public function author() + public function author(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } - public function blog_post_comment() + public function blog_post_comment(): BelongsTo { return $this->belongsTo(BlogPostComment::class, 'blog_post_comment_id'); } - public function scopeForBlogPostCommentsUpVote($query, BlogPostComment $comment) + public function scopeForBlogPostCommentsUpVote(Builder $query, BlogPostComment $comment): Builder { return $query->where('blog_post_comment_id', $comment->id)->where('type', 'upvote'); } - public function scopeForBlogPostCommentsDownVote($query, BlogPostComment $comment) + public function scopeForBlogPostCommentsDownVote(Builder $query, BlogPostComment $comment): Builder { return $query->where('blog_post_comment_id', $comment->id)->where('type', 'downvote'); } diff --git a/app/Models/BlogPostLike.php b/app/Models/BlogPostLike.php index 8bd09d0..121556e 100644 --- a/app/Models/BlogPostLike.php +++ b/app/Models/BlogPostLike.php @@ -2,18 +2,43 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +/** + * App\Models\BlogPostLike + * + * @property int $id + * @property int $blog_post_id + * @property int $user_id + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostLike forBlogPost(\App\Models\BlogPost $blogPost) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostLike newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostLike newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostLike query() + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostLike whereBlogPostId($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostLike whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostLike whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostLike whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|BlogPostLike whereUserId($value) + * + * @mixin \Eloquent + */ class BlogPostLike extends Model { use HasFactory; + /** + * @var array + */ protected $fillable = [ 'user_id', ]; - public function scopeForBlogPost($query, BlogPost $blogPost) + public function scopeForBlogPost(Builder $query, BlogPost $blogPost): Builder { return $query->where('blog_post_id', $blogPost->id); } diff --git a/app/Models/Calendar.php b/app/Models/Calendar.php index 83eccb3..f947851 100644 --- a/app/Models/Calendar.php +++ b/app/Models/Calendar.php @@ -5,6 +5,22 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +/** + * App\Models\Calendar + * + * @property int $id + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @method static \Illuminate\Database\Eloquent\Builder|Calendar newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Calendar newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Calendar query() + * @method static \Illuminate\Database\Eloquent\Builder|Calendar whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Calendar whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Calendar whereUpdatedAt($value) + * + * @mixin \Eloquent + */ class Calendar extends Model { use HasFactory; diff --git a/app/Models/Chat.php b/app/Models/Chat.php index 4c18529..e49063e 100644 --- a/app/Models/Chat.php +++ b/app/Models/Chat.php @@ -2,16 +2,42 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +/** + * App\Models\Chat + * + * @property int $id + * @property int $from_user_id + * @property int $to_user_id + * @property string $data + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @method static \Illuminate\Database\Eloquent\Builder|Chat newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Chat newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Chat query() + * @method static \Illuminate\Database\Eloquent\Builder|Chat whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Chat whereData($value) + * @method static \Illuminate\Database\Eloquent\Builder|Chat whereFromUserId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Chat whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Chat whereToUserId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Chat whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Chat withLastMessage(int $userId, int $recipientId) + * @method static \Illuminate\Database\Eloquent\Builder|Chat withLastTenMessages(int $userId, int $recipientId) + * @method static \Illuminate\Database\Eloquent\Builder|Chat withLastUserMessage(int $userId) + * + * @mixin \Eloquent + */ class Chat extends Model { use HasFactory; 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 { return $query ->where('from_user_id', $userId) @@ -20,12 +46,12 @@ 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) ->where('to_user_id', $recipientId) - ->orWhere(function ($query) use ($userId, $recipientId) { + ->orWhere(function (Builder $query) use ($userId, $recipientId) { return $query->where('from_user_id', $recipientId) ->where('to_user_id', $userId); }) @@ -33,12 +59,12 @@ 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 { return $query ->where('from_user_id', $userId) ->where('to_user_id', $recipientId) - ->orWhere(function ($query) use ($userId, $recipientId) { + ->orWhere(function (Builder $query) use ($userId, $recipientId) { return $query->where('from_user_id', $recipientId) ->where('to_user_id', $userId); }) diff --git a/app/Models/ChosenDiet.php b/app/Models/ChosenDiet.php index 7bcfed7..6522260 100644 --- a/app/Models/ChosenDiet.php +++ b/app/Models/ChosenDiet.php @@ -5,7 +5,37 @@ 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 + * + * @property int $id + * @property int|null $diet_id + * @property int $user_id + * @property string $last_state + * @property string $start_date + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\Diet|null $diet + * @property-read \Illuminate\Database\Eloquent\Collection $stateHistory + * @property-read int|null $state_history_count + * @property-read \App\Models\User|null $user + * + * @method static \Illuminate\Database\Eloquent\Builder|ChosenDiet newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ChosenDiet newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ChosenDiet query() + * @method static \Illuminate\Database\Eloquent\Builder|ChosenDiet whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|ChosenDiet whereDietId($value) + * @method static \Illuminate\Database\Eloquent\Builder|ChosenDiet whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|ChosenDiet whereLastState($value) + * @method static \Illuminate\Database\Eloquent\Builder|ChosenDiet whereStartDate($value) + * @method static \Illuminate\Database\Eloquent\Builder|ChosenDiet whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|ChosenDiet whereUserId($value) + * + * @mixin \Eloquent + */ class ChosenDiet extends Model { use HasFactory, Statable; @@ -17,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; } diff --git a/app/Models/ChosenPlan.php b/app/Models/ChosenPlan.php index 26dfc74..e1009c8 100644 --- a/app/Models/ChosenPlan.php +++ b/app/Models/ChosenPlan.php @@ -4,12 +4,39 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +/** + * App\Models\ChosenPlan + * + * @property int $id + * @property int|null $plan_id + * @property int $user_id + * @property string $last_state + * @property string $start_date + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\User|null $user + * + * @method static \Illuminate\Database\Eloquent\Builder|ChosenPlan newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ChosenPlan newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ChosenPlan query() + * @method static \Illuminate\Database\Eloquent\Builder|ChosenPlan whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|ChosenPlan whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|ChosenPlan whereLastState($value) + * @method static \Illuminate\Database\Eloquent\Builder|ChosenPlan wherePlanId($value) + * @method static \Illuminate\Database\Eloquent\Builder|ChosenPlan whereStartDate($value) + * @method static \Illuminate\Database\Eloquent\Builder|ChosenPlan whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|ChosenPlan whereUserId($value) + * + * @mixin \Eloquent + */ class ChosenPlan extends Model { use HasFactory; - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Models/CircumferenceMeasure.php b/app/Models/CircumferenceMeasure.php index 7b44e3d..5a22243 100644 --- a/app/Models/CircumferenceMeasure.php +++ b/app/Models/CircumferenceMeasure.php @@ -4,14 +4,41 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +/** + * App\Models\CircumferenceMeasure + * + * @property int $id + * @property int $user_id + * @property int $chest_circumference + * @property int $waist_circumference + * @property int $hip_circumference + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\User|null $user + * + * @method static \Illuminate\Database\Eloquent\Builder|CircumferenceMeasure newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|CircumferenceMeasure newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|CircumferenceMeasure query() + * @method static \Illuminate\Database\Eloquent\Builder|CircumferenceMeasure whereChestCircumference($value) + * @method static \Illuminate\Database\Eloquent\Builder|CircumferenceMeasure whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|CircumferenceMeasure whereHipCircumference($value) + * @method static \Illuminate\Database\Eloquent\Builder|CircumferenceMeasure whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|CircumferenceMeasure whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|CircumferenceMeasure whereUserId($value) + * @method static \Illuminate\Database\Eloquent\Builder|CircumferenceMeasure whereWaistCircumference($value) + * + * @mixin \Eloquent + */ class CircumferenceMeasure extends Model { use HasFactory; protected $guarded = []; - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Models/CommentUpvote.php b/app/Models/CommentUpvote.php index 8149a85..befe36d 100644 --- a/app/Models/CommentUpvote.php +++ b/app/Models/CommentUpvote.php @@ -2,9 +2,38 @@ 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\CommentUpvote + * + * @property int $id + * @property int $comment_id + * @property int $user_id + * @property string $type + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\User|null $author + * @property-read \App\Models\PlanComment|null $plan_comment + * + * @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote forPlanCommentsDownVote(\App\Models\PlanComment $comment) + * @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote forPlanCommentsUpVote(\App\Models\PlanComment $comment) + * @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote query() + * @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote whereCommentId($value) + * @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote whereType($value) + * @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|CommentUpvote whereUserId($value) + * + * @mixin \Eloquent + */ class CommentUpvote extends Model { use HasFactory; @@ -15,22 +44,22 @@ class CommentUpvote extends Model 'type', ]; - public function plan_comment() + public function plan_comment(): BelongsTo { return $this->belongsTo(PlanComment::class, 'comment_id'); } - public function author() + public function author(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } - public function scopeForPlanCommentsUpVote($query, PlanComment $comment) + public function scopeForPlanCommentsUpVote(Builder $query, PlanComment $comment): Builder { return $query->where('comment_id', $comment->id)->where('type', 'upvote'); } - public function scopeForPlanCommentsDownVote($query, PlanComment $comment) + public function scopeForPlanCommentsDownVote(Builder $query, PlanComment $comment): Builder { return $query->where('comment_id', $comment->id)->where('type', 'downvote'); } diff --git a/app/Models/ConsultantDiaryComment.php b/app/Models/ConsultantDiaryComment.php index 8ecbc0e..31f33a2 100644 --- a/app/Models/ConsultantDiaryComment.php +++ b/app/Models/ConsultantDiaryComment.php @@ -5,6 +5,30 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +/** + * App\Models\ConsultantDiaryComment + * + * @property int $id + * @property int $user_id consultant id + * @property int $diary_id + * @property string $comment_type + * @property string $comment + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantDiaryComment newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantDiaryComment newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantDiaryComment query() + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantDiaryComment whereComment($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantDiaryComment whereCommentType($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantDiaryComment whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantDiaryComment whereDiaryId($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantDiaryComment whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantDiaryComment whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantDiaryComment whereUserId($value) + * + * @mixin \Eloquent + */ class ConsultantDiaryComment extends Model { use HasFactory; diff --git a/app/Models/ConsultantEducation.php b/app/Models/ConsultantEducation.php index 07f2910..b2efdef 100644 --- a/app/Models/ConsultantEducation.php +++ b/app/Models/ConsultantEducation.php @@ -4,14 +4,49 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +/** + * App\Models\ConsultantEducation + * + * @property int $id + * @property int $user_id + * @property mixed $completed_courses + * @property int $has_medical_education + * @property string $vk_link + * @property string $insta_link + * @property string $fb_link + * @property string $tg_link + * @property string $request_state + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\User|null $user + * + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation query() + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation whereCompletedCourses($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation whereFbLink($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation whereHasMedicalEducation($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation whereInstaLink($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation whereRequestState($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation whereTgLink($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation whereUserId($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantEducation whereVkLink($value) + * + * @mixin \Eloquent + */ class ConsultantEducation extends Model { use HasFactory; protected $guarded = []; - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Models/ConsultantLegalEntity.php b/app/Models/ConsultantLegalEntity.php index 476be35..95c2268 100644 --- a/app/Models/ConsultantLegalEntity.php +++ b/app/Models/ConsultantLegalEntity.php @@ -6,6 +6,56 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +/** + * App\Models\ConsultantLegalEntity + * + * @property int $id + * @property int $user_id + * @property string $type ip|selfemployed|ltd + * @property string $inn ИНН + * @property string $egrip Номер записи в ЕГРИП для ИП + * @property string $ltd_name Название OOO + * @property string $ltd_kpp КПП ООО + * @property string $ltd_ogrn ОГРН ООО + * @property string $ltd_legal_address Юридический адрес ООО + * @property string $ltd_poste_address Почтовый адрес ООО + * @property string $ltd_okved ОКВЭД ООО + * @property string $ltd_ceo_name ФИО Генерального директора ООО + * @property string $bank_account Рассчетный счет + * @property string $bank_correspondent_account корреспондентский счет + * @property string $bank_bik БИК + * @property string $bank_name Название Банка + * @property string $state published|appruved|cenceled + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\User $user + * + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity query() + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereBankAccount($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereBankBik($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereBankCorrespondentAccount($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereBankName($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereEgrip($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereInn($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereLtdCeoName($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereLtdKpp($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereLtdLegalAddress($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereLtdName($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereLtdOgrn($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereLtdOkved($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereLtdPosteAddress($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereState($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereType($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|ConsultantLegalEntity whereUserId($value) + * + * @mixin \Eloquent + */ class ConsultantLegalEntity extends Model { use HasFactory; diff --git a/app/Models/Diary.php b/app/Models/Diary.php index 22a380b..7fbdc81 100644 --- a/app/Models/Diary.php +++ b/app/Models/Diary.php @@ -2,10 +2,49 @@ 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 + * + * @property int $id + * @property int|null $user_id + * @property string $date + * @property string $wakeup + * @property string $retire + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * @property int|bool $closed + * @property string $comment + * + * @property-read \Illuminate\Database\Eloquent\Collection $consultant_comments + * @property-read int|null $consultant_comments_count + * @property-read \Illuminate\Database\Eloquent\Collection $meals + * @property-read int|null $meals_count + * @property-read \App\Models\User|null $user + * + * @method static \Database\Factories\DiaryFactory factory($count = null, $state = []) + * @method static \Illuminate\Database\Eloquent\Builder|Diary newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Diary newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Diary query() + * @method static \Illuminate\Database\Eloquent\Builder|Diary userToDayItem($userId) + * @method static \Illuminate\Database\Eloquent\Builder|Diary whereClosed($value) + * @method static \Illuminate\Database\Eloquent\Builder|Diary whereComment($value) + * @method static \Illuminate\Database\Eloquent\Builder|Diary whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Diary whereDate($value) + * @method static \Illuminate\Database\Eloquent\Builder|Diary whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Diary whereRetire($value) + * @method static \Illuminate\Database\Eloquent\Builder|Diary whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Diary whereUserId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Diary whereWakeup($value) + * + * @mixin \Eloquent + */ class Diary extends Model { use HasFactory; @@ -13,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); } diff --git a/app/Models/Diet.php b/app/Models/Diet.php index fe4d9a8..3ea5808 100644 --- a/app/Models/Diet.php +++ b/app/Models/Diet.php @@ -8,26 +8,87 @@ 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; +/** + * App\Models\Diet + * + * @property int $id + * @property string $name name of diet + * @property string|null $image public path to image + * @property int $duration diet duration - 7, 14, 28 days + * @property string $state active/draft/archived + * @property mixed $type has meat/vegs/carb/alcohol + * @property string $details diet details + * @property mixed $daily_schedule A list of planned foods + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \Illuminate\Database\Eloquent\Collection $author + * @property-read int|null $author_count + * @property-read \Illuminate\Database\Eloquent\Collection $choses + * @property-read int|null $choses_count + * @property-read \Illuminate\Database\Eloquent\Collection $comments + * @property-read int|null $comments_count + * @property-read \Illuminate\Database\Eloquent\Collection $likes + * @property-read int|null $likes_count + * @property-read \Illuminate\Database\Eloquent\Collection $views + * @property-read int|null $views_count + * + * @method static Builder|Diet containsType($types) + * @method static Builder|Diet durationMax($days) + * @method static Builder|Diet durationMin($days) + * @method static \Database\Factories\DietFactory factory($count = null, $state = []) + * @method static Builder|Diet involvedMax($number) + * @method static Builder|Diet involvedMin($number) + * @method static Builder|Diet newModelQuery() + * @method static Builder|Diet newQuery() + * @method static Builder|Diet orderByUniqueViews(string $direction = 'desc', $period = null, ?string $collection = null, string $as = 'unique_views_count') + * @method static Builder|Diet orderByViews(string $direction = 'desc', ?\CyrildeWit\EloquentViewable\Support\Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count') + * @method static Builder|Diet query() + * @method static Builder|Diet whereCreatedAt($value) + * @method static Builder|Diet whereDailySchedule($value) + * @method static Builder|Diet whereDetails($value) + * @method static Builder|Diet whereDuration($value) + * @method static Builder|Diet whereId($value) + * @method static Builder|Diet whereImage($value) + * @method static Builder|Diet whereName($value) + * @method static Builder|Diet whereState($value) + * @method static Builder|Diet whereType($value) + * @method static Builder|Diet whereUpdatedAt($value) + * @method static Builder|Diet withViewsCount(?\CyrildeWit\EloquentViewable\Support\Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count') + * + * @mixin \Eloquent + */ 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'); @@ -40,7 +101,7 @@ class Diet extends Model implements Viewable );*/ } - public function comments() + public function comments(): HasMany { return $this->hasMany(DietComment::class); } @@ -50,16 +111,16 @@ 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(); + return auth()->user()->diet_likes()->forDiet($this)->count() > 0; } return false; } - public function removeLike(): bool + public function removeLike(): bool|int { if (auth()->user()) { return auth()->user()->diet_likes()->forDiet($this)->delete(); @@ -70,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), @@ -79,39 +140,39 @@ 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; @@ -126,13 +187,4 @@ class Diet extends Model implements Viewable 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); - } } diff --git a/app/Models/DietComment.php b/app/Models/DietComment.php index e0605a2..96447ce 100644 --- a/app/Models/DietComment.php +++ b/app/Models/DietComment.php @@ -4,18 +4,48 @@ 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; +/** + * App\Models\DietComment + * + * @property int $id + * @property int $user_id + * @property int $diet_id + * @property int $grade + * @property string|null $body + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\User $author + * @property-read \App\Models\Diet|null $diet + * @property-read \Illuminate\Database\Eloquent\Collection $upvotes + * @property-read int|null $upvotes_count + * + * @method static \Illuminate\Database\Eloquent\Builder|DietComment newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|DietComment newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|DietComment query() + * @method static \Illuminate\Database\Eloquent\Builder|DietComment whereBody($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietComment whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietComment whereDietId($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietComment whereGrade($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietComment whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietComment whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietComment whereUserId($value) + * + * @mixin \Eloquent + */ 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'); } @@ -25,33 +55,33 @@ 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() ->user() ->diet_comment_upvotes() ->forDietCommentsUpVote($this) - ->count(); + ->count() > 0; } return false; } - public function isDownVoted(): bool + public function isDownVoted(): bool|int { if (auth()->user()) { return auth() ->user() ->diet_comment_upvotes() ->forDietCommentsDownVote($this) - ->count(); + ->count() > 0; } return false; } - public function removeUpVote(): bool + public function removeUpVote(): bool|int { if (auth()->user()) { return auth() diff --git a/app/Models/DietCommentUpvote.php b/app/Models/DietCommentUpvote.php index de7ee0b..09edda7 100644 --- a/app/Models/DietCommentUpvote.php +++ b/app/Models/DietCommentUpvote.php @@ -2,9 +2,38 @@ 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 + * + * @property int $id + * @property int $comment_id + * @property int $user_id + * @property string $type + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\User $author + * @property-read \App\Models\DietComment|null $diet_comment + * + * @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote forDietCommentsDownVote(\App\Models\DietComment $comment) + * @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote forDietCommentsUpVote(\App\Models\DietComment $comment) + * @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote query() + * @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote whereCommentId($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote whereType($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietCommentUpvote whereUserId($value) + * + * @mixin \Eloquent + */ class DietCommentUpvote extends Model { use HasFactory; @@ -15,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'); } diff --git a/app/Models/DietLike.php b/app/Models/DietLike.php index 550e1b8..d856e23 100644 --- a/app/Models/DietLike.php +++ b/app/Models/DietLike.php @@ -2,9 +2,31 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +/** + * App\Models\DietLike + * + * @property int $id + * @property int $diet_id + * @property int $user_id + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @method static \Illuminate\Database\Eloquent\Builder|DietLike forDiet(\App\Models\Diet $diet) + * @method static \Illuminate\Database\Eloquent\Builder|DietLike newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|DietLike newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|DietLike query() + * @method static \Illuminate\Database\Eloquent\Builder|DietLike whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietLike whereDietId($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietLike whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietLike whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|DietLike whereUserId($value) + * + * @mixin \Eloquent + */ class DietLike extends Model { use HasFactory; @@ -13,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); } diff --git a/app/Models/Finance.php b/app/Models/Finance.php index c0cccf4..19981e5 100644 --- a/app/Models/Finance.php +++ b/app/Models/Finance.php @@ -5,6 +5,22 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +/** + * App\Models\Finance + * + * @property int $id + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @method static \Illuminate\Database\Eloquent\Builder|Finance newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Finance newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Finance query() + * @method static \Illuminate\Database\Eloquent\Builder|Finance whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Finance whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Finance whereUpdatedAt($value) + * + * @mixin \Eloquent + */ class Finance extends Model { use HasFactory; diff --git a/app/Models/Meal.php b/app/Models/Meal.php index d782376..bb60b59 100644 --- a/app/Models/Meal.php +++ b/app/Models/Meal.php @@ -4,31 +4,69 @@ 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 + * + * @property int $id + * @property int|null $user_id + * @property int|null $diary_id + * @property string $time + * @property int $type + * @property int $satiety + * @property int $mood + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\Diary|null $diary + * @property-read \Illuminate\Database\Eloquent\Collection $photos + * @property-read int|null $photos_count + * @property-read \Illuminate\Database\Eloquent\Collection $portions + * @property-read int|null $portions_count + * @property-read \App\Models\User|null $user + * + * @method static \Illuminate\Database\Eloquent\Builder|Meal newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Meal newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Meal query() + * @method static \Illuminate\Database\Eloquent\Builder|Meal whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Meal whereDiaryId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Meal whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Meal whereMood($value) + * @method static \Illuminate\Database\Eloquent\Builder|Meal whereSatiety($value) + * @method static \Illuminate\Database\Eloquent\Builder|Meal whereTime($value) + * @method static \Illuminate\Database\Eloquent\Builder|Meal whereType($value) + * @method static \Illuminate\Database\Eloquent\Builder|Meal whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Meal whereUserId($value) + * + * @mixin \Eloquent + */ class Meal extends Model { use HasFactory; 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); } diff --git a/app/Models/Plan.php b/app/Models/Plan.php index 2167a42..ecea57c 100644 --- a/app/Models/Plan.php +++ b/app/Models/Plan.php @@ -9,11 +9,65 @@ 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; use Laracasts\Presenter\PresentableTrait; use Spatie\Sluggable\HasSlug; use Spatie\Sluggable\SlugOptions; +/** + * App\Models\Plan + * + * @property int $id + * @property string $name name of plan + * @property string|null $image public path to image + * @property int $duration plan duration - 7, 14, 21 days + * @property string $state active/draft/archived + * @property array $type to lose weight, to gain weight, to improve your mood, to shape your eating behavior + * @property string $details plan details + * @property int $packets_count 1 on 3 packets of options in plan + * @property array $packet1_options + * @property array $packet2_options + * @property array $packet3_options + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * @property string $slug + * + * @property-read \Illuminate\Database\Eloquent\Collection $author + * @property-read int|null $author_count + * @property-read \Illuminate\Database\Eloquent\Collection $comments + * @property-read int|null $comments_count + * @property-read \Illuminate\Database\Eloquent\Collection $likes + * @property-read int|null $likes_count + * @property-read \Illuminate\Database\Eloquent\Collection $views + * @property-read int|null $views_count + * + * @method static \Database\Factories\PlanFactory factory($count = null, $state = []) + * @method static Builder|Plan negativeComments() + * @method static Builder|Plan newModelQuery() + * @method static Builder|Plan newQuery() + * @method static Builder|Plan orderByUniqueViews(string $direction = 'desc', $period = null, ?string $collection = null, string $as = 'unique_views_count') + * @method static Builder|Plan orderByViews(string $direction = 'desc', ?\CyrildeWit\EloquentViewable\Support\Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count') + * @method static Builder|Plan positiveComments() + * @method static Builder|Plan query() + * @method static Builder|Plan whereCreatedAt($value) + * @method static Builder|Plan whereDetails($value) + * @method static Builder|Plan whereDuration($value) + * @method static Builder|Plan whereId($value) + * @method static Builder|Plan whereImage($value) + * @method static Builder|Plan whereName($value) + * @method static Builder|Plan wherePacket1Options($value) + * @method static Builder|Plan wherePacket2Options($value) + * @method static Builder|Plan wherePacket3Options($value) + * @method static Builder|Plan wherePacketsCount($value) + * @method static Builder|Plan whereSlug($value) + * @method static Builder|Plan whereState($value) + * @method static Builder|Plan whereType($value) + * @method static Builder|Plan whereUpdatedAt($value) + * @method static Builder|Plan withViewsCount(?\CyrildeWit\EloquentViewable\Support\Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count') + * + * @mixin \Eloquent + */ class Plan extends Model implements Viewable { use HasFactory; @@ -21,27 +75,6 @@ class Plan extends Model implements Viewable use InteractsWithViews; use PresentableTrait; - public function getSlugOptions(): SlugOptions - { - return SlugOptions::create() - ->generateSlugsFrom(['name']) - ->saveSlugsTo('slug') - // ->slugsShouldBeNoLongerThan(20) - ->usingSeparator('_'); - // ->usingLanguage('ru') - // ->doNotGenerateSlugsOnUpdate(); - } - - /** - * Get the route key for the model. - * - * @return string - */ - public function getRouteKeyName() - { - return 'slug'; - } - protected $withCount = [ 'likes', 'comments', @@ -54,14 +87,27 @@ class Plan extends Model implements Viewable 'packet3_options' => 'array', ]; - protected $presenter = PlanPresenter::class; + protected string $presenter = PlanPresenter::class; - public function author() + public function getSlugOptions(): SlugOptions + { + return SlugOptions::create() + ->generateSlugsFrom(['name']) + ->saveSlugsTo('slug') + ->usingSeparator('_'); + } + + public function getRouteKeyName(): string + { + return 'slug'; + } + + public function author(): BelongsToMany { return $this->belongsToMany(User::class, 'plan_author', 'plan_id', 'user_id'); } - public function comments() + public function comments(): HasMany { return $this->hasMany(PlanComment::class); } @@ -71,7 +117,7 @@ class Plan extends Model implements Viewable return $this->hasMany(PlanLike::class); } - public function isLiked(): bool + public function isLiked(): bool|int { if (auth()->user()) { return auth()->user()->plan_likes()->forPlan($this)->count(); @@ -86,7 +132,6 @@ class Plan extends Model implements Viewable for ($i = 1; $i <= $this->packets_count; $i++) { $key = 'packet'.$i.'_options'; - // $data = $this->unserializeOptionsObj($this->$key); $data = $this->$key; if (! is_null($data)) { $result = array_merge($result, data_get($data, 'items', [])); @@ -98,7 +143,6 @@ class Plan extends Model implements Viewable public function types(): Attribute { - // $data = $this->unserializeOptionsArr($this->type); $data = $this->type; return new Attribute( @@ -111,8 +155,6 @@ class Plan extends Model implements Viewable $result = 0; for ($i = 1; $i <= $this->packets_count; $i++) { $key = 'packet'.$i.'_options'; - // dd($this->$key); - // $data = $this->unserializeOptionsObj($this->$key); $data = $this->$key; if (! is_null($data)) { $curPrice = (int) data_get($data, 'price', 0); @@ -134,31 +176,13 @@ class Plan extends Model implements Viewable return false; } - public function scopeNegativeComments(Builder $query) + public function scopeNegativeComments(): HasMany { return static::comments()->where('grade', '<=', '3'); } - public function scopePositiveComments(Builder $query) + public function scopePositiveComments(): HasMany { return static::comments()->where('grade', '>', '3'); } - - private function unserializeOptionsObj($str) - { - if (preg_match('/^".*"$/', $str)) { - return json_decode(stripslashes(mb_substr($str, 1, -1))); - } - - return json_decode(stripslashes($str)); - } - - private function unserializeOptionsArr($str) - { - if (preg_match('/^".*"$/', $str)) { - return json_decode(stripslashes(mb_substr($str, 1, -1)), true); - } - - return json_decode(stripslashes($str), true); - } } diff --git a/app/Models/PlanComment.php b/app/Models/PlanComment.php index 5869b3d..6e0f678 100644 --- a/app/Models/PlanComment.php +++ b/app/Models/PlanComment.php @@ -4,18 +4,49 @@ 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; +/** + * App\Models\PlanComment + * + * @property int $id + * @property int $user_id + * @property int $plan_id + * @property int $grade + * @property string|null $body + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\User $author + * @property-read \App\Models\Plan|null $plan + * @property-read \Illuminate\Database\Eloquent\Collection $upvotes + * @property-read int|null $upvotes_count + * + * @method static \Database\Factories\PlanCommentFactory factory($count = null, $state = []) + * @method static \Illuminate\Database\Eloquent\Builder|PlanComment newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|PlanComment newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|PlanComment query() + * @method static \Illuminate\Database\Eloquent\Builder|PlanComment whereBody($value) + * @method static \Illuminate\Database\Eloquent\Builder|PlanComment whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|PlanComment whereGrade($value) + * @method static \Illuminate\Database\Eloquent\Builder|PlanComment whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|PlanComment wherePlanId($value) + * @method static \Illuminate\Database\Eloquent\Builder|PlanComment whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|PlanComment whereUserId($value) + * + * @mixin \Eloquent + */ class PlanComment extends Model { use HasFactory; - public function author() + public function author(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } - public function plan() + public function plan(): BelongsTo { return $this->belongsTo(Plan::class, 'plan_id'); } @@ -25,7 +56,7 @@ class PlanComment extends Model return $this->hasMany(CommentUpvote::class, 'comment_id'); } - public function isUpVoted(): bool + public function isUpVoted(): bool|int { if (auth()->user()) { return auth() @@ -38,7 +69,7 @@ class PlanComment extends Model return false; } - public function isDownVoted(): bool + public function isDownVoted(): bool|int { if (auth()->user()) { return auth() diff --git a/app/Models/PlanLike.php b/app/Models/PlanLike.php index f33eddd..a55b4d4 100644 --- a/app/Models/PlanLike.php +++ b/app/Models/PlanLike.php @@ -2,9 +2,31 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +/** + * App\Models\PlanLike + * + * @property int $id + * @property int $plan_id + * @property int $user_id + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @method static \Illuminate\Database\Eloquent\Builder|PlanLike forPlan(\App\Models\Plan $plan) + * @method static \Illuminate\Database\Eloquent\Builder|PlanLike newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|PlanLike newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|PlanLike query() + * @method static \Illuminate\Database\Eloquent\Builder|PlanLike whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|PlanLike whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|PlanLike wherePlanId($value) + * @method static \Illuminate\Database\Eloquent\Builder|PlanLike whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|PlanLike whereUserId($value) + * + * @mixin \Eloquent + */ class PlanLike extends Model { use HasFactory; @@ -13,7 +35,7 @@ class PlanLike extends Model 'user_id', ]; - public function scopeForPlan($query, Plan $plan) + public function scopeForPlan(Builder $query, Plan $plan): Builder { return $query->where('plan_id', $plan->id); } diff --git a/app/Models/Portion.php b/app/Models/Portion.php index 7355001..e8e63b1 100644 --- a/app/Models/Portion.php +++ b/app/Models/Portion.php @@ -4,14 +4,41 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +/** + * App\Models\Portion + * + * @property int $id + * @property int $meal_id + * @property string $product_name + * @property string $portion + * @property int $quantity + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\Meal $user + * + * @method static \Illuminate\Database\Eloquent\Builder|Portion newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Portion newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Portion query() + * @method static \Illuminate\Database\Eloquent\Builder|Portion whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Portion whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Portion whereMealId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Portion wherePortion($value) + * @method static \Illuminate\Database\Eloquent\Builder|Portion whereProductName($value) + * @method static \Illuminate\Database\Eloquent\Builder|Portion whereQuantity($value) + * @method static \Illuminate\Database\Eloquent\Builder|Portion whereUpdatedAt($value) + * + * @mixin \Eloquent + */ class Portion extends Model { use HasFactory; protected $fillable = ['*']; - public function user() + public function user(): BelongsTo { return $this->belongsTo(Meal::class); } diff --git a/app/Models/ProductGroup.php b/app/Models/ProductGroup.php index b239ee6..81e7070 100644 --- a/app/Models/ProductGroup.php +++ b/app/Models/ProductGroup.php @@ -4,14 +4,38 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; +/** + * App\Models\ProductGroup + * + * @property int $id + * @property string $name + * @property string $description + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \Illuminate\Database\Eloquent\Collection $product_nutritional_value + * @property-read int|null $product_nutritional_value_count + * + * @method static \Illuminate\Database\Eloquent\Builder|ProductGroup newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ProductGroup newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ProductGroup query() + * @method static \Illuminate\Database\Eloquent\Builder|ProductGroup whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductGroup whereDescription($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductGroup whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductGroup whereName($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductGroup whereUpdatedAt($value) + * + * @mixin \Eloquent + */ class ProductGroup extends Model { use HasFactory; protected $fillable = ['name']; - public function product_nutritional_value() + public function product_nutritional_value(): HasMany { return $this->hasMany(ProductNutritionalValue::class); } diff --git a/app/Models/ProductNutritionalValue.php b/app/Models/ProductNutritionalValue.php index 276f15a..358d394 100644 --- a/app/Models/ProductNutritionalValue.php +++ b/app/Models/ProductNutritionalValue.php @@ -4,14 +4,61 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +/** + * App\Models\ProductNutritionalValue + * + * @property int $id + * @property string $name + * @property string|null $image + * @property int $product_group_id + * @property string $description + * @property string $formulations + * @property int $energy_on_100gr + * @property float $proteins_on_100gr + * @property float $fats_on_100gr + * @property float $carbohydrates_on_100gr + * @property int $portion_mass_gr + * @property float $energy_on_portion + * @property float $proteins_on_portion + * @property float $fats_on_portion + * @property float $carbohydrates_on_portion + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\ProductGroup|null $product_group + * + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue query() + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereCarbohydratesOn100gr($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereCarbohydratesOnPortion($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereDescription($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereEnergyOn100gr($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereEnergyOnPortion($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereFatsOn100gr($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereFatsOnPortion($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereFormulations($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereImage($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereName($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue wherePortionMassGr($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereProductGroupId($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereProteinsOn100gr($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereProteinsOnPortion($value) + * @method static \Illuminate\Database\Eloquent\Builder|ProductNutritionalValue whereUpdatedAt($value) + * + * @mixin \Eloquent + */ class ProductNutritionalValue extends Model { use HasFactory; protected $guarded = []; - public function product_group() + public function product_group(): BelongsTo { return $this->belongsTo(ProductGroup::class); } diff --git a/app/Models/Recipe.php b/app/Models/Recipe.php index b7250ff..e398055 100755 --- a/app/Models/Recipe.php +++ b/app/Models/Recipe.php @@ -4,19 +4,75 @@ namespace App\Models; use CyrildeWit\EloquentViewable\Contracts\Viewable; use CyrildeWit\EloquentViewable\InteractsWithViews; +use Illuminate\Contracts\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Casts\AsCollection; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Contracts\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Relations\HasOneThrough; +use Illuminate\Database\Eloquent\Relations\MorphToMany; +use Illuminate\Support\Str; use Spatie\Sluggable\HasSlug; use Spatie\Sluggable\SlugOptions; +/** + * App\Models\Recipe + * + * @property int $id + * @property string $image public path to image + * @property string $state active/archived + * @property int $cooking_time + * @property AsCollection|array $ingredients + * @property string $description + * @property AsCollection|array $steps + * @property string $video_url + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * @property string $title + * @property string $type + * @property string $slug + * + * @property-read \App\Models\User $author + * @property-read \Illuminate\Database\Eloquent\Collection $comments + * @property-read int|null $comments_count + * @property-read \Illuminate\Database\Eloquent\Collection $likes + * @property-read int|null $likes_count + * @property-read \Illuminate\Database\Eloquent\Collection $tags + * @property-read int|null $tags_count + * @property-read \Illuminate\Database\Eloquent\Collection $views + * @property-read int|null $views_count + * + * @method static \Illuminate\Database\Eloquent\Builder|Recipe containsTag($tagString) + * @method static \Database\Factories\RecipeFactory factory($count = null, $state = []) + * @method static \Illuminate\Database\Eloquent\Builder|Recipe negativeComments() + * @method static \Illuminate\Database\Eloquent\Builder|Recipe newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Recipe newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Recipe orderByUniqueViews(string $direction = 'desc', $period = null, ?string $collection = null, string $as = 'unique_views_count') + * @method static \Illuminate\Database\Eloquent\Builder|Recipe orderByViews(string $direction = 'desc', ?\CyrildeWit\EloquentViewable\Support\Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count') + * @method static \Illuminate\Database\Eloquent\Builder|Recipe positiveComments() + * @method static \Illuminate\Database\Eloquent\Builder|Recipe query() + * @method static \Illuminate\Database\Eloquent\Builder|Recipe whereCookingTime($value) + * @method static \Illuminate\Database\Eloquent\Builder|Recipe whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Recipe whereDescription($value) + * @method static \Illuminate\Database\Eloquent\Builder|Recipe whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Recipe whereImage($value) + * @method static \Illuminate\Database\Eloquent\Builder|Recipe whereIngredients($value) + * @method static \Illuminate\Database\Eloquent\Builder|Recipe whereSlug($value) + * @method static \Illuminate\Database\Eloquent\Builder|Recipe whereState($value) + * @method static \Illuminate\Database\Eloquent\Builder|Recipe whereSteps($value) + * @method static \Illuminate\Database\Eloquent\Builder|Recipe whereTitle($value) + * @method static \Illuminate\Database\Eloquent\Builder|Recipe whereType($value) + * @method static \Illuminate\Database\Eloquent\Builder|Recipe whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Recipe whereVideoUrl($value) + * @method static \Illuminate\Database\Eloquent\Builder|Recipe withViewsCount(?\CyrildeWit\EloquentViewable\Support\Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count') + * + * @mixin \Eloquent + */ class Recipe extends Model implements Viewable { use HasFactory; - use InteractsWithViews; use HasSlug; + use InteractsWithViews; protected $casts = [ 'steps' => AsCollection::class, @@ -39,27 +95,17 @@ class Recipe extends Model implements Viewable // ->doNotGenerateSlugsOnUpdate(); } - /** - * Get the route key for the model. - * - * @return string - */ - public function getRouteKeyName() + public function getRouteKeyName(): string { return 'slug'; } - public function tags() + public function tags(): MorphToMany { return $this->morphToMany(Tag::class, 'taggable'); } - /* public function author() */ - /* { */ - /* return $this->belongsToMany(User::class, 'recipe_author', 'recipe_id', 'user_id'); */ - /* } */ - - public function author() + public function author(): HasOneThrough { return $this ->hasOneThrough(User::class, RecipeAuthor::class, 'recipe_id', 'id', 'id', 'user_id') @@ -72,7 +118,7 @@ class Recipe extends Model implements Viewable ); } - public function comments() + public function comments(): HasMany { return $this->hasMany(RecipeComment::class); } @@ -82,18 +128,17 @@ class Recipe extends Model implements Viewable return $this->hasMany(RecipeLike::class); } - - public function scopeNegativeComments(Builder $query) + public function scopeNegativeComments(): Builder { return static::comments()->where('grade', '<=', '3'); } - public function scopePositiveComments(Builder $query) + public function scopePositiveComments(): Builder { return static::comments()->where('grade', '>', '3'); } - public function isLiked(): bool + public function isLiked(): bool|int { $curUser = auth()->user(); if ($curUser) { @@ -103,7 +148,7 @@ class Recipe extends Model implements Viewable return false; } - public function removeLike(): bool + public function removeLike(): bool|int { $curUser = auth()->user(); if ($curUser) { @@ -113,7 +158,7 @@ class Recipe extends Model implements Viewable return false; } - public function scopeContainsTag($query, $tagString): Builder + public function scopeContainsTag(Builder $query, string $tagString): Builder { $tagId = Str::of($tagString)->split('/-/')->first(); diff --git a/app/Models/RecipeAuthor.php b/app/Models/RecipeAuthor.php index 69287b4..ccbe555 100644 --- a/app/Models/RecipeAuthor.php +++ b/app/Models/RecipeAuthor.php @@ -5,6 +5,20 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +/** + * App\Models\RecipeAuthor + * + * @property int $user_id + * @property int $recipe_id + * + * @method static \Illuminate\Database\Eloquent\Builder|RecipeAuthor newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|RecipeAuthor newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|RecipeAuthor query() + * @method static \Illuminate\Database\Eloquent\Builder|RecipeAuthor whereRecipeId($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeAuthor whereUserId($value) + * + * @mixin \Eloquent + */ class RecipeAuthor extends Model { use HasFactory; diff --git a/app/Models/RecipeComment.php b/app/Models/RecipeComment.php index 80adff8..e34bcea 100644 --- a/app/Models/RecipeComment.php +++ b/app/Models/RecipeComment.php @@ -4,18 +4,49 @@ 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; +/** + * App\Models\RecipeComment + * + * @property int $id + * @property int $user_id + * @property int $recipe_id + * @property int $grade + * @property string|null $body + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\User $author + * @property-read \App\Models\Recipe|null $recipe + * @property-read \Illuminate\Database\Eloquent\Collection $upvotes + * @property-read int|null $upvotes_count + * + * @method static \Database\Factories\RecipeCommentFactory factory($count = null, $state = []) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment query() + * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment whereBody($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment whereGrade($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment whereRecipeId($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeComment whereUserId($value) + * + * @mixin \Eloquent + */ class RecipeComment extends Model { use HasFactory; - public function author() + public function author(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } - public function recipe() + public function recipe(): BelongsTo { return $this->belongsTo(Recipe::class, 'recipe_id'); } @@ -25,7 +56,7 @@ class RecipeComment extends Model return $this->hasMany(RecipeCommentUpvote::class, 'recipe_comment_id'); } - public function isUpVoted(): bool + public function isUpVoted(): bool|int { $curUser = auth()->user(); if ($curUser) { @@ -38,7 +69,7 @@ class RecipeComment extends Model return false; } - public function isDownVoted(): bool + public function isDownVoted(): bool|int { $curUser = auth()->user(); if ($curUser) { @@ -51,7 +82,7 @@ class RecipeComment extends Model return false; } - public function removeUpVote(): bool + public function removeUpVote(): bool|int { $curUser = auth()->user(); if ($curUser) { @@ -64,7 +95,7 @@ class RecipeComment extends Model return false; } - public function removeDownVote(): bool + public function removeDownVote(): bool|int { $curUser = auth()->user(); if ($curUser) { diff --git a/app/Models/RecipeCommentUpvote.php b/app/Models/RecipeCommentUpvote.php index 789aba8..54ce6ec 100644 --- a/app/Models/RecipeCommentUpvote.php +++ b/app/Models/RecipeCommentUpvote.php @@ -2,9 +2,38 @@ 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\RecipeCommentUpvote + * + * @property int $id + * @property int $recipe_comment_id + * @property int $user_id + * @property string $type + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\User $author + * @property-read \App\Models\BlogPostComment|null $recipe_comment + * + * @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote forRecipeCommentsDownVote(\App\Models\RecipeComment $comment) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote forRecipeCommentsUpVote(\App\Models\RecipeComment $comment) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote query() + * @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote whereRecipeCommentId($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote whereType($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeCommentUpvote whereUserId($value) + * + * @mixin \Eloquent + */ class RecipeCommentUpvote extends Model { use HasFactory; @@ -15,22 +44,22 @@ class RecipeCommentUpvote extends Model 'type', ]; - public function author() + public function author(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } - public function recipe_comment() + public function recipe_comment(): BelongsTo { return $this->belongsTo(BlogPostComment::class, 'recipe_comment_id'); } - public function scopeForRecipeCommentsUpVote($query, RecipeComment $comment) + public function scopeForRecipeCommentsUpVote(Builder $query, RecipeComment $comment): Builder { return $query->where('recipe_comment_id', $comment->id)->where('type', 'upvote'); } - public function scopeForRecipeCommentsDownVote($query, RecipeComment $comment) + public function scopeForRecipeCommentsDownVote(Builder $query, RecipeComment $comment): Builder { return $query->where('recipe_comment_id', $comment->id)->where('type', 'downvote'); } diff --git a/app/Models/RecipeLike.php b/app/Models/RecipeLike.php index 784815c..93a51e2 100644 --- a/app/Models/RecipeLike.php +++ b/app/Models/RecipeLike.php @@ -2,9 +2,31 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +/** + * App\Models\RecipeLike + * + * @property int $id + * @property int $recipe_id + * @property int $user_id + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @method static \Illuminate\Database\Eloquent\Builder|RecipeLike forRecipe(\App\Models\Recipe $recipe) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeLike newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|RecipeLike newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|RecipeLike query() + * @method static \Illuminate\Database\Eloquent\Builder|RecipeLike whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeLike whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeLike whereRecipeId($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeLike whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|RecipeLike whereUserId($value) + * + * @mixin \Eloquent + */ class RecipeLike extends Model { use HasFactory; @@ -13,7 +35,7 @@ class RecipeLike extends Model 'user_id', ]; - public function scopeForRecipe($query, Recipe $recipe) + public function scopeForRecipe(Builder $query, Recipe $recipe): Builder { return $query->where('recipe_id', $recipe->id); } diff --git a/app/Models/Tag.php b/app/Models/Tag.php index 12db58d..179918e 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -5,20 +5,45 @@ namespace App\Models; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\MorphToMany; use Illuminate\Support\Str; +/** + * App\Models\Tag + * + * @property int $id + * @property string $name + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \Illuminate\Database\Eloquent\Collection $blogPosts + * @property-read int|null $blog_posts_count + * @property-read \Illuminate\Database\Eloquent\Collection $recipes + * @property-read int|null $recipes_count + * + * @method static \Database\Factories\TagFactory factory($count = null, $state = []) + * @method static \Illuminate\Database\Eloquent\Builder|Tag newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Tag newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Tag query() + * @method static \Illuminate\Database\Eloquent\Builder|Tag whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|Tag whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|Tag whereName($value) + * @method static \Illuminate\Database\Eloquent\Builder|Tag whereUpdatedAt($value) + * + * @mixin \Eloquent + */ class Tag extends Model { use HasFactory; protected $guarded = []; - public function blogPosts() + public function blogPosts(): MorphToMany { return $this->morphedByMany(BlogPost::class, 'taggable', 'taggables'); } - public function recipes() + public function recipes(): MorphToMany { return $this->morphedByMany(Recipe::class, 'taggable', 'taggables'); } diff --git a/app/Models/User.php b/app/Models/User.php index 8e13ff7..c7fb7ec 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -17,6 +17,107 @@ use Laravel\Fortify\TwoFactorAuthenticatable; use Laravel\Jetstream\HasProfilePhoto; use Laravel\Sanctum\HasApiTokens; +/** + * App\Models\User + * + * @property int $id + * @property string $name + * @property string $email + * @property \Illuminate\Support\Carbon|null $email_verified_at + * @property string $password + * @property string|null $two_factor_secret + * @property string|null $two_factor_recovery_codes + * @property string|null $two_factor_confirmed_at + * @property string|null $remember_token + * @property int|null $current_team_id + * @property string|null $profile_photo_path + * @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 $attachments + * @property-read int|null $attachments_count + * @property-read \Illuminate\Database\Eloquent\Collection $author_of_blog_post + * @property-read int|null $author_of_blog_post_count + * @property-read \Illuminate\Database\Eloquent\Collection $author_of_diets + * @property-read int|null $author_of_diets_count + * @property-read \Illuminate\Database\Eloquent\Collection $author_of_plans + * @property-read int|null $author_of_plans_count + * @property-read \Illuminate\Database\Eloquent\Collection $author_of_recipe + * @property-read int|null $author_of_recipe_count + * @property-read \Illuminate\Database\Eloquent\Collection $blog_post_comment_upvotes + * @property-read int|null $blog_post_comment_upvotes_count + * @property-read \Illuminate\Database\Eloquent\Collection $blog_post_comments + * @property-read int|null $blog_post_comments_count + * @property-read \Illuminate\Database\Eloquent\Collection $blog_post_likes + * @property-read int|null $blog_post_likes_count + * @property-read \App\Models\ChosenDiet|null $chosen_diet + * @property-read \App\Models\ChosenPlan|null $chosen_plan + * @property-read \Illuminate\Database\Eloquent\Collection $circumference_measures + * @property-read int|null $circumference_measures_count + * @property-read \Illuminate\Database\Eloquent\Collection $comment_upvotes + * @property-read int|null $comment_upvotes_count + * @property-read \App\Models\ConsultantLegalEntity|null $consultant_legal_entity + * @property-read \App\Models\ConsultantEducation|null $consultant_request + * @property-read \App\Models\UserDetailz|null $detailz + * @property-read \Illuminate\Database\Eloquent\Collection $diaries + * @property-read int|null $diaries_count + * @property-read \Illuminate\Database\Eloquent\Collection $diet_comment_upvotes + * @property-read int|null $diet_comment_upvotes_count + * @property-read \Illuminate\Database\Eloquent\Collection $diet_comments + * @property-read int|null $diet_comments_count + * @property-read \Illuminate\Database\Eloquent\Collection $diet_likes + * @property-read int|null $diet_likes_count + * @property-read \Illuminate\Database\Eloquent\Collection $meals + * @property-read int|null $meals_count + * @property-read \Illuminate\Notifications\DatabaseNotificationCollection $notifications + * @property-read int|null $notifications_count + * @property-read \Illuminate\Database\Eloquent\Collection $plan_comments + * @property-read int|null $plan_comments_count + * @property-read \Illuminate\Database\Eloquent\Collection $plan_likes + * @property-read int|null $plan_likes_count + * @property-read string $profile_photo_url + * @property-read \Illuminate\Database\Eloquent\Collection $recipe_comment_upvotes + * @property-read int|null $recipe_comment_upvotes_count + * @property-read \Illuminate\Database\Eloquent\Collection $recipe_comments + * @property-read int|null $recipe_comments_count + * @property-read \Illuminate\Database\Eloquent\Collection $recipe_likes + * @property-read int|null $recipe_likes_count + * @property-read \Illuminate\Database\Eloquent\Collection $tokens + * @property-read int|null $tokens_count + * @property-read \Illuminate\Database\Eloquent\Collection $views + * @property-read int|null $views_count + * @property-read \Illuminate\Database\Eloquent\Collection $weight_measures + * @property-read int|null $weight_measures_count + * @property-read string $consultant_state + * + * @method static \Database\Factories\UserFactory factory($count = null, $state = []) + * @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|User newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|User orderByUniqueViews(string $direction = 'desc', $period = null, ?string $collection = null, string $as = 'unique_views_count') + * @method static \Illuminate\Database\Eloquent\Builder|User orderByViews(string $direction = 'desc', ?\CyrildeWit\EloquentViewable\Support\Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count') + * @method static \Illuminate\Database\Eloquent\Builder|User query() + * @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|User whereCurrentTeamId($value) + * @method static \Illuminate\Database\Eloquent\Builder|User whereEmail($value) + * @method static \Illuminate\Database\Eloquent\Builder|User whereEmailVerifiedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|User whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|User whereIsConsultant($value) + * @method static \Illuminate\Database\Eloquent\Builder|User whereIsPublicProfile($value) + * @method static \Illuminate\Database\Eloquent\Builder|User whereName($value) + * @method static \Illuminate\Database\Eloquent\Builder|User wherePassword($value) + * @method static \Illuminate\Database\Eloquent\Builder|User whereProfilePhotoPath($value) + * @method static \Illuminate\Database\Eloquent\Builder|User whereRememberToken($value) + * @method static \Illuminate\Database\Eloquent\Builder|User whereTwoFactorConfirmedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|User whereTwoFactorRecoveryCodes($value) + * @method static \Illuminate\Database\Eloquent\Builder|User whereTwoFactorSecret($value) + * @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|User withViewsCount(?\CyrildeWit\EloquentViewable\Support\Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count') + * + * @mixin \Eloquent + */ class User extends Authenticatable implements MustVerifyEmail, Viewable { use HasApiTokens; diff --git a/app/Models/UserAttachment.php b/app/Models/UserAttachment.php index c4a40be..f166877 100644 --- a/app/Models/UserAttachment.php +++ b/app/Models/UserAttachment.php @@ -2,26 +2,62 @@ 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 + * + * @property int $id + * @property int $user_id + * @property string $group + * @property string $original_name + * @property string $path + * @property int $size + * @property mixed $specs + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \Illuminate\Database\Eloquent\Collection $meals + * @property-read int|null $meals_count + * @property-read \App\Models\User $user + * + * @method static \Illuminate\Database\Eloquent\Builder|UserAttachment certs() + * @method static \Illuminate\Database\Eloquent\Builder|UserAttachment newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|UserAttachment newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|UserAttachment query() + * @method static \Illuminate\Database\Eloquent\Builder|UserAttachment whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserAttachment whereGroup($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserAttachment whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserAttachment whereOriginalName($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserAttachment wherePath($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserAttachment whereSize($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserAttachment whereSpecs($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserAttachment whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserAttachment whereUserId($value) + * + * @mixin \Eloquent + */ class UserAttachment extends Model { use HasFactory; 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); } diff --git a/app/Models/UserDetailz.php b/app/Models/UserDetailz.php index b3d17e3..d8eb549 100644 --- a/app/Models/UserDetailz.php +++ b/app/Models/UserDetailz.php @@ -4,14 +4,84 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +/** + * App\Models\UserDetailz + * + * @property int $id + * @property int|null $user_id + * @property string $first_name + * @property string $last_name + * @property string $birthdate + * @property string $gender + * @property string $country + * @property string $city + * @property string $lang + * @property int $weight + * @property int $height user height in centimeters + * @property int $chest_circumference + * @property int $waist_circumference + * @property int $hip_circumference + * @property int $blood_pressure_up + * @property int $blood_pressure_down + * @property int $has_hypo + * @property int $has_hyper + * @property string $about_alergy + * @property string $about_taking_pils + * @property string $about_sport_hobbies + * @property string $favorite_foods + * @property string $unfavorite_foods + * @property string $additional_info + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * @property int $is_mood_fillable + * @property int $is_bedtime_fillable + * + * @property-read \App\Models\User|null $user + * + * @method static \Database\Factories\UserDetailzFactory factory($count = null, $state = []) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz query() + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereAboutAlergy($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereAboutSportHobbies($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereAboutTakingPils($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereAdditionalInfo($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereBirthdate($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereBloodPressureDown($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereBloodPressureUp($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereChestCircumference($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereCity($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereCountry($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereFavoriteFoods($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereFirstName($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereGender($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereHasHyper($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereHasHypo($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereHeight($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereHipCircumference($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereIsBedtimeFillable($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereIsMoodFillable($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereLang($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereLastName($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereUnfavoriteFoods($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereUserId($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereWaistCircumference($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserDetailz whereWeight($value) + * + * @mixin \Eloquent + */ class UserDetailz extends Model { use HasFactory; protected $guarded = []; - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Models/WeightMeasure.php b/app/Models/WeightMeasure.php index e7a7ca8..0890418 100644 --- a/app/Models/WeightMeasure.php +++ b/app/Models/WeightMeasure.php @@ -4,14 +4,37 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +/** + * App\Models\WeightMeasure + * + * @property int $id + * @property int $user_id + * @property int $weight + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * + * @property-read \App\Models\User $user + * + * @method static \Illuminate\Database\Eloquent\Builder|WeightMeasure newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|WeightMeasure newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|WeightMeasure query() + * @method static \Illuminate\Database\Eloquent\Builder|WeightMeasure whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|WeightMeasure whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|WeightMeasure whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|WeightMeasure whereUserId($value) + * @method static \Illuminate\Database\Eloquent\Builder|WeightMeasure whereWeight($value) + * + * @mixin \Eloquent + */ class WeightMeasure extends Model { use HasFactory; protected $guarded = []; - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Notifications/ConsultantRequestStarted.php b/app/Notifications/ConsultantRequestStarted.php index ff31650..0bb9d67 100644 --- a/app/Notifications/ConsultantRequestStarted.php +++ b/app/Notifications/ConsultantRequestStarted.php @@ -12,7 +12,7 @@ class ConsultantRequestStarted extends Notification implements ShouldQueue { use Queueable; - private ConsultantEducation $education; + public ConsultantEducation $education; /** * Create a new notification instance. @@ -39,7 +39,7 @@ class ConsultantRequestStarted extends Notification implements ShouldQueue public function toMail(object $notifiable): MailMessage { return (new MailMessage()) - ->subject('[Eatvio] New Consultant request') + ->subject('[Eatvio] New Consultant ['.$this->education->user_id.'] request') ->line('User: '.$notifiable->name.' send Consultant request') ->action('Notification Action', route('profile.show', $notifiable)) ->line('Thank you for using our application!'); diff --git a/app/Notifications/DietStarted.php b/app/Notifications/DietStarted.php index 2bab49a..4c4ed18 100644 --- a/app/Notifications/DietStarted.php +++ b/app/Notifications/DietStarted.php @@ -11,51 +11,31 @@ 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) + ->line('you are successful started diet named: '.($this->chosenDiet->diet->name ?? 'NoName')) ->action('Notification Action', route('diet.show', $this->chosenDiet->diet)) ->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 [ diff --git a/app/Presenters/PlanPresenter.php b/app/Presenters/PlanPresenter.php index 7c5bf3e..b414553 100644 --- a/app/Presenters/PlanPresenter.php +++ b/app/Presenters/PlanPresenter.php @@ -2,19 +2,23 @@ namespace App\Presenters; +use App\Models\User; use Illuminate\Support\Facades\Storage; use Laracasts\Presenter\Presenter; +/** + * @property User $author + */ class PlanPresenter extends Presenter { - public function getAuthorPhoto() + public function getAuthorPhoto(): string { $author = $this->getAuthor(); return Storage::url($author->profile_photo_path); } - public function getAuthor() + public function getAuthor(): User { return $this->author->first(); } diff --git a/app/Rules/MinWords.php b/app/Rules/MinWords.php index 929a924..c04582d 100644 --- a/app/Rules/MinWords.php +++ b/app/Rules/MinWords.php @@ -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."; } diff --git a/app/Services/FeedService.php b/app/Services/FeedService.php index 13a322c..ecefd06 100644 --- a/app/Services/FeedService.php +++ b/app/Services/FeedService.php @@ -6,66 +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 { - $days = 5; $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); } } diff --git a/composer.lock b/composer.lock index 1bf3663..0b5414c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f1504229d84c399a1c8aea12005e3530", + "content-hash": "afc6808a42647b1794df47cf2ee58a35", "packages": [ { "name": "aalaap/faker-youtube", @@ -13868,4 +13868,3 @@ "platform-dev": [], "plugin-api-version": "2.6.0" } - diff --git a/config/insights.php b/config/insights.php index b6284e6..bf5c663 100644 --- a/config/insights.php +++ b/config/insights.php @@ -65,6 +65,7 @@ return [ */ 'exclude' => [ + '/application/app/Livewire', // 'path/to/directory-or-file' ], diff --git a/config/rich-text-laravel.php b/config/rich-text-laravel.php index 3c1f439..4d85ec1 100644 --- a/config/rich-text-laravel.php +++ b/config/rich-text-laravel.php @@ -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, /* |-------------------------------------------------------------------------- diff --git a/config/state-machine.php b/config/state-machine.php index 8bbf7c2..c18dbb5 100644 --- a/config/state-machine.php +++ b/config/state-machine.php @@ -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', diff --git a/database/assets/images/blogPosts/1.jpg b/database/assets/images/blogPosts/1.jpg new file mode 100644 index 0000000..109d54b Binary files /dev/null and b/database/assets/images/blogPosts/1.jpg differ diff --git a/database/assets/images/blogPosts/10.jpg b/database/assets/images/blogPosts/10.jpg new file mode 100644 index 0000000..f741713 Binary files /dev/null and b/database/assets/images/blogPosts/10.jpg differ diff --git a/database/assets/images/blogPosts/2.jpg b/database/assets/images/blogPosts/2.jpg new file mode 100644 index 0000000..d9678ed Binary files /dev/null and b/database/assets/images/blogPosts/2.jpg differ diff --git a/database/assets/images/blogPosts/3.jpg b/database/assets/images/blogPosts/3.jpg new file mode 100644 index 0000000..486d99a Binary files /dev/null and b/database/assets/images/blogPosts/3.jpg differ diff --git a/database/assets/images/blogPosts/4.jpg b/database/assets/images/blogPosts/4.jpg new file mode 100644 index 0000000..a733364 Binary files /dev/null and b/database/assets/images/blogPosts/4.jpg differ diff --git a/database/assets/images/blogPosts/5.jpg b/database/assets/images/blogPosts/5.jpg new file mode 100644 index 0000000..60afe23 Binary files /dev/null and b/database/assets/images/blogPosts/5.jpg differ diff --git a/database/assets/images/blogPosts/6.jpg b/database/assets/images/blogPosts/6.jpg new file mode 100644 index 0000000..dea5e63 Binary files /dev/null and b/database/assets/images/blogPosts/6.jpg differ diff --git a/database/assets/images/blogPosts/7.jpg b/database/assets/images/blogPosts/7.jpg new file mode 100644 index 0000000..296e4d2 Binary files /dev/null and b/database/assets/images/blogPosts/7.jpg differ diff --git a/database/assets/images/blogPosts/8.jpg b/database/assets/images/blogPosts/8.jpg new file mode 100644 index 0000000..1c4af7f Binary files /dev/null and b/database/assets/images/blogPosts/8.jpg differ diff --git a/database/assets/images/blogPosts/9.jpg b/database/assets/images/blogPosts/9.jpg new file mode 100644 index 0000000..ed5d6c8 Binary files /dev/null and b/database/assets/images/blogPosts/9.jpg differ diff --git a/database/assets/images/plans/1.jpg b/database/assets/images/plans/1.jpg new file mode 100644 index 0000000..0c1a0bd Binary files /dev/null and b/database/assets/images/plans/1.jpg differ diff --git a/database/assets/images/plans/10.jpg b/database/assets/images/plans/10.jpg new file mode 100644 index 0000000..5da0e76 Binary files /dev/null and b/database/assets/images/plans/10.jpg differ diff --git a/database/assets/images/plans/2.jpg b/database/assets/images/plans/2.jpg new file mode 100644 index 0000000..bb6a09d Binary files /dev/null and b/database/assets/images/plans/2.jpg differ diff --git a/database/assets/images/plans/3.jpg b/database/assets/images/plans/3.jpg new file mode 100644 index 0000000..7c191c6 Binary files /dev/null and b/database/assets/images/plans/3.jpg differ diff --git a/database/assets/images/plans/4.jpg b/database/assets/images/plans/4.jpg new file mode 100644 index 0000000..2be94a0 Binary files /dev/null and b/database/assets/images/plans/4.jpg differ diff --git a/database/assets/images/plans/5.jpg b/database/assets/images/plans/5.jpg new file mode 100644 index 0000000..b5ac735 Binary files /dev/null and b/database/assets/images/plans/5.jpg differ diff --git a/database/assets/images/plans/6.jpg b/database/assets/images/plans/6.jpg new file mode 100644 index 0000000..d9dc298 Binary files /dev/null and b/database/assets/images/plans/6.jpg differ diff --git a/database/assets/images/plans/7.jpg b/database/assets/images/plans/7.jpg new file mode 100644 index 0000000..71533b4 Binary files /dev/null and b/database/assets/images/plans/7.jpg differ diff --git a/database/assets/images/plans/8.jpg b/database/assets/images/plans/8.jpg new file mode 100644 index 0000000..37e2bde Binary files /dev/null and b/database/assets/images/plans/8.jpg differ diff --git a/database/assets/images/plans/9.jpg b/database/assets/images/plans/9.jpg new file mode 100644 index 0000000..e31a465 Binary files /dev/null and b/database/assets/images/plans/9.jpg differ diff --git a/database/assets/images/recipes/1.jpg b/database/assets/images/recipes/1.jpg new file mode 100644 index 0000000..567b61a Binary files /dev/null and b/database/assets/images/recipes/1.jpg differ diff --git a/database/assets/images/recipes/10.jpg b/database/assets/images/recipes/10.jpg new file mode 100644 index 0000000..afc6910 Binary files /dev/null and b/database/assets/images/recipes/10.jpg differ diff --git a/database/assets/images/recipes/2.jpg b/database/assets/images/recipes/2.jpg new file mode 100644 index 0000000..d5abdbc Binary files /dev/null and b/database/assets/images/recipes/2.jpg differ diff --git a/database/assets/images/recipes/3.jpg b/database/assets/images/recipes/3.jpg new file mode 100644 index 0000000..5c0b6db Binary files /dev/null and b/database/assets/images/recipes/3.jpg differ diff --git a/database/assets/images/recipes/4.jpg b/database/assets/images/recipes/4.jpg new file mode 100644 index 0000000..95b82b4 Binary files /dev/null and b/database/assets/images/recipes/4.jpg differ diff --git a/database/assets/images/recipes/5.jpg b/database/assets/images/recipes/5.jpg new file mode 100644 index 0000000..1de5fe2 Binary files /dev/null and b/database/assets/images/recipes/5.jpg differ diff --git a/database/assets/images/recipes/6.jpg b/database/assets/images/recipes/6.jpg new file mode 100644 index 0000000..8b8ac1c Binary files /dev/null and b/database/assets/images/recipes/6.jpg differ diff --git a/database/assets/images/recipes/7.jpg b/database/assets/images/recipes/7.jpg new file mode 100644 index 0000000..75a28be Binary files /dev/null and b/database/assets/images/recipes/7.jpg differ diff --git a/database/assets/images/recipes/8.jpg b/database/assets/images/recipes/8.jpg new file mode 100644 index 0000000..a4b0d80 Binary files /dev/null and b/database/assets/images/recipes/8.jpg differ diff --git a/database/assets/images/recipes/9.jpg b/database/assets/images/recipes/9.jpg new file mode 100644 index 0000000..1a2d55b Binary files /dev/null and b/database/assets/images/recipes/9.jpg differ diff --git a/database/factories/BlogPostCommentFactory.php b/database/factories/BlogPostCommentFactory.php new file mode 100644 index 0000000..99d1795 --- /dev/null +++ b/database/factories/BlogPostCommentFactory.php @@ -0,0 +1,25 @@ + + */ +class BlogPostCommentFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'grade' => $this->faker->randomDigit(), + 'body' => $this->faker->text(), + ]; + + } +} diff --git a/database/factories/BlogPostFactory.php b/database/factories/BlogPostFactory.php index 1780ea6..51f2a20 100644 --- a/database/factories/BlogPostFactory.php +++ b/database/factories/BlogPostFactory.php @@ -4,10 +4,15 @@ 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 Faker\Provider\Youtube; +use Faker\Generator; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\BlogPost> + * + * @property Generator|Youtube $faker */ class BlogPostFactory extends Factory { @@ -20,28 +25,27 @@ class BlogPostFactory extends Factory */ public function definition() { - $imagePath = storage_path('app/public'); - $curImage = $this->faker->image($imagePath.'/blog_posts', 360, 360, 'animals', true, true, 'cats', true, 'jpg'); - $curImage = Str::replace($imagePath, '', $curImage); + $faker = \Faker\Factory::create(); + $this->faker->addProvider(new Youtube($faker)); return [ 'state' => $this->faker->randomElement(['active', 'archived']), - 'image' => $curImage, + 'image' => $this->generateImageFile('blog_post'), 'description' => $this->faker->realText($this->faker->numberBetween(100, 200)), - 'youtube_url' => $this->faker->url(), - 'created_at' => $this->faker->dateTimeBetween('-1 week', '+1 week'), - 'updated_at' => $this->faker->dateTimeBetween('-1 week', '+1 week'), + 'youtube_url' => $this->faker->youtubeRandomUri(), 'title' => $this->faker->realText($this->faker->numberBetween(10, 20)), ]; } - public function some() + private function generateImageFile(string $name): string { - User::orderBy('created_at', 'desc')->limit(20)->get()->map(function ($user) { - $newBlogPosts = BlogPost::factory()->count(3)->create(); - $newBlogPosts->map(function ($post) use ($user) { - $user->author_of_blog_post()->attach($post->id); - }); - }); + $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/blogPosts/' . $images[$imageFileKey]; + $file = new File($imageFilePath); + $fileLocalPath = Storage::putFile($name, $file, 'public'); + + return $fileLocalPath; } } diff --git a/database/factories/DietFactory.php b/database/factories/DietFactory.php index d4917be..d347845 100644 --- a/database/factories/DietFactory.php +++ b/database/factories/DietFactory.php @@ -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, diff --git a/database/factories/PlanFactory.php b/database/factories/PlanFactory.php index 85c690d..e90477d 100755 --- a/database/factories/PlanFactory.php +++ b/database/factories/PlanFactory.php @@ -4,11 +4,13 @@ namespace Database\Factories; use FakerRestaurant\Provider\en_US\Restaurant; use Illuminate\Database\Eloquent\Factories\Factory; -use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; +use Illuminate\Http\File; +use Faker\Generator; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Plan> + * @property Generator|Restaurant $faker */ class PlanFactory extends Factory { @@ -16,10 +18,10 @@ class PlanFactory extends Factory * Define the model's default state. * * @return array + * */ public function definition(): array { - $faker = \Faker\Factory::create(); $this->faker->addProvider(new Restaurant($faker)); @@ -41,7 +43,6 @@ class PlanFactory extends Factory 'description' => $this->faker->text(), ]; - $packetsOptions2 = [ 'items' => [$this->faker->fruitName(), $this->faker->meatName(), $this->faker->sauceName()], 'price' => $this->faker->randomNumber(), @@ -49,7 +50,6 @@ class PlanFactory extends Factory 'description' => $this->faker->text(), ]; - $packetsOptions3 = [ 'items' => [$this->faker->fruitName(), $this->faker->meatName(), $this->faker->sauceName()], 'price' => $this->faker->randomNumber(), @@ -57,17 +57,11 @@ class PlanFactory extends Factory 'description' => $this->faker->text(), ]; - Storage::fake('plans'); - $file = UploadedFile::fake()->image('plan.png'); - $fileLocalPath = $file->store('plans', 'public'); - return [ 'name' => $this->faker->foodName(), - // 'image' => UploadedFile::fake()->image('plans/Photo_C.png'), - 'image' => $fileLocalPath, + 'image' => $this->generateImageFile(), 'duration' => $this->faker->randomElement([7, 14, 21]), 'state' => $this->faker->randomElement(['active', 'draft', 'unactive']), - //'type' => $this->faker->randomElement([$typeBody, $wrongTypeBody]), 'type' => $typeBody, 'details' => $this->faker->text(), 'packets_count' => $active ? 3 : 1, @@ -76,4 +70,16 @@ class PlanFactory extends Factory 'packet3_options' => $active ? $packetsOptions3 : '', ]; } + + 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; + } } diff --git a/database/factories/ProductGroupFactory.php b/database/factories/ProductGroupFactory.php new file mode 100644 index 0000000..5802f3f --- /dev/null +++ b/database/factories/ProductGroupFactory.php @@ -0,0 +1,28 @@ + + * @property Generator|Restaurant $faker + */ +class ProductGroupFactory extends Factory +{ + /** + * @return array + */ + 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)), + ]; + } +} diff --git a/database/factories/ProductNutritionalValueFactory.php b/database/factories/ProductNutritionalValueFactory.php new file mode 100644 index 0000000..9abae55 --- /dev/null +++ b/database/factories/ProductNutritionalValueFactory.php @@ -0,0 +1,57 @@ + + * @property Generator|Restaurant $faker + */ class ProductNutritionalValueFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + * + */ + 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; + } +} diff --git a/database/factories/RecipeCommentFactory.php b/database/factories/RecipeCommentFactory.php index bea271f..83c31ff 100644 --- a/database/factories/RecipeCommentFactory.php +++ b/database/factories/RecipeCommentFactory.php @@ -7,7 +7,7 @@ namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; /** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PlanComment> + * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\RecipeComment> */ class RecipeCommentFactory extends Factory { diff --git a/database/factories/RecipeFactory.php b/database/factories/RecipeFactory.php index edf251e..537c4b1 100644 --- a/database/factories/RecipeFactory.php +++ b/database/factories/RecipeFactory.php @@ -1,17 +1,19 @@ - + * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Recipe> + * + * @property Generator|Restaurant|Youtube $faker */ class RecipeFactory extends Factory { @@ -30,7 +32,7 @@ class RecipeFactory extends Factory 'title' => $this->faker->foodName(), 'image' => $this->generateImageFile('recipes'), 'state' => $this->faker->randomElement(['active', 'archived']), - 'cooking_time' => $this->faker->numberBetween(0, 59), + 'cooking_time' => $this->faker->randomElement(['10', '20', '30', '60', '120', '14400']), 'ingredients' => $this->createQuentityIngredients($this->faker->randomDigitNotNull()), // quentity - от 1 до 10 randomDigitNotNull 'type' => $this->faker->randomElement(['first_meals', 'second_meals', 'salads', 'snacks', 'drinks', 'other']), 'description' => $this->faker->text(), @@ -39,18 +41,23 @@ class RecipeFactory extends Factory ]; } - private function generateImageFile(string $name) + private function generateImageFile(string $name): 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); - $file = UploadedFile::fake()->image($name . '.png'); - return $file->store($name, 'public'); + $imageFileKey = $this->faker->numberBetween(0, 9); + $imageFilePath = 'database/assets/images/recipes/' . $images[$imageFileKey]; + $file = new File($imageFilePath); + $fileLocalPath = Storage::putFile($name, $file, 'public'); + + return $fileLocalPath; } private function generateIngredients(): array { return [ 'name' => $this->faker->foodName(), - 'unit' => $this->faker->randomElement(['гр', 'ч. ложек', 'cт. ложек', 'мл', 'шт', 'зубчик', 'по вкусу']), + 'unit' => $this->faker->randomElement(['gr', 'teespons', 'tablespoon', 'ml', 'pcs', 'clove', 'to_taste']), 'portion' => $this->faker->randomNumber(3, true), ]; } @@ -63,7 +70,7 @@ class RecipeFactory extends Factory ]; } - private function createQuentitySteps($count) + private function createQuentitySteps(int $count): array { $result = []; @@ -74,7 +81,7 @@ class RecipeFactory extends Factory return $result; } - private function createQuentityIngredients($count) + private function createQuentityIngredients(int $count): array { $result = []; diff --git a/database/factories/TagFactory.php b/database/factories/TagFactory.php index 5bb5ba1..bb769dc 100644 --- a/database/factories/TagFactory.php +++ b/database/factories/TagFactory.php @@ -1,14 +1,14 @@ - + * @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(), ]; diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 563d0f4..af6289e 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -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> diff --git a/database/migrations/2023_07_26_150531_create_product_nutritional_values_table.php b/database/migrations/2023_07_26_150531_create_product_nutritional_values_table.php index 0a4e630..6f74520 100644 --- a/database/migrations/2023_07_26_150531_create_product_nutritional_values_table.php +++ b/database/migrations/2023_07_26_150531_create_product_nutritional_values_table.php @@ -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'); } diff --git a/database/seeders/BlogPostSeeder.php b/database/seeders/BlogPostSeeder.php index a5e4c02..9e8ce08 100644 --- a/database/seeders/BlogPostSeeder.php +++ b/database/seeders/BlogPostSeeder.php @@ -3,16 +3,62 @@ namespace Database\Seeders; use Illuminate\Database\Seeder; +use App\Models\BlogPost; +use App\Models\User; +use App\Models\BlogPostComment; +use App\Models\Tag; class BlogPostSeeder extends Seeder { /** * Run the database seeds. - * - * @return void */ - public function run() + public function run(): void { - // + $blogPosts = BlogPost::factory()->count(10)->create(); + + if (User::count() > 0 && BlogPost::count() > 0) { + + $blogPosts->each( + function ($blogPost) { + User::inRandomOrder() + ->first() + ->author_of_blog_post() + ->attach($blogPost->id); + } + ); + + $comments = BlogPostComment::factory()->count(5)->make(); + + $comments->each( + static function ($comment): void { + $comment->author()->associate( + User::inRandomOrder() + ->first() + ->id + ); + + $comment->blog_post()->associate( + BlogPost::inRandomOrder() + ->first() + ->id + ); + + $comment->saveOrFail(); + } + ); + + $blogPosts = BlogPost::all(); + + $blogPosts->each( + static function ($blogPost): void { + + $tags = Tag::factory()->count(5)->create(); + + $tagsIds = collect($tags)->map(fn($curTag) => $curTag['id']); + $blogPost->tags()->attach($tagsIds); + } + ); + } } } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 0be680a..f58c5d8 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -18,5 +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); } } diff --git a/database/seeders/ProductNutritionalSeeder.php b/database/seeders/ProductNutritionalSeeder.php new file mode 100644 index 0000000..17f2975 --- /dev/null +++ b/database/seeders/ProductNutritionalSeeder.php @@ -0,0 +1,24 @@ +count(5)->make(); + + $products->each( + function ($product) { + $product->product_group()->associate(ProductGroup::factory()->create()); + return $product->saveOrFail(); + } + ); + } +} diff --git a/lang/ru/recipe.php b/lang/ru/recipe.php index c4fc380..c39386e 100644 --- a/lang/ru/recipe.php +++ b/lang/ru/recipe.php @@ -15,6 +15,7 @@ return [ 't10m' => '10 минут', 't20m' => '20 минут', 't30m' => '30 минут', + 't45m' => '45 минут', 't60m' => '1 час', 't120m' => '2 час', 't14400m' => '10 дней', diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 3cc4503..c968996 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -17,11 +17,11 @@ parameters: excludePaths: - vendor/* + - database/* + - tests/* - app/Http/Controllers/Auth/* + - config/* + - routes/* ignoreErrors: - - '/Parameter #1 \$value of function collect expects/' - - '/PHPDoc type array of property App\\Models\\User::\$hidden is not covariant with PHPDoc type/' - - '/PHPDoc type array of property App\\Models\\User::\$casts is not covariant with PHPDoc type/' - '/Unable to resolve the template type TKey in call to function collect/' - '/Unable to resolve the template type TValue in call to function collect/' - - '/is not covariant with PHPDoc type/' diff --git a/public/css/app.css b/public/css/app.css index 89d015b..cb66aa5 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -13709,7 +13709,10 @@ video { color: #fff; }.active-icon-heart{ color: #2f80ed; -}/* Recipe-show like */.text-blue-400 { color: #2f80ed; }.text-blue-500 { color: #2f80ed;}.text-gray-400 { color: #cbd5e0; }.text-gray-500 { color: #a0aec0; }@media (prefers-color-scheme: dark) {.dark\:prose-invert { +}/* Recipe-show like */.text-blue-400 { color: #2f80ed; }.text-blue-500 { color: #2f80ed;}.text-gray-400 { color: #cbd5e0; }.text-gray-500 { color: #a0aec0; }.review__info { + min-width: 120px; + width: 120px; +}@media (prefers-color-scheme: dark) {.dark\:prose-invert { --tw-prose-body: var(--tw-prose-invert-body); --tw-prose-headings: var(--tw-prose-invert-headings); --tw-prose-lead: var(--tw-prose-invert-lead); diff --git a/rector.php b/rector.php index fdad3c1..d823d25 100644 --- a/rector.php +++ b/rector.php @@ -1,13 +1,11 @@ paths([ __DIR__ . '/app', __DIR__ . '/bootstrap', @@ -26,4 +24,3 @@ return function (RectorConfig $rectorConfig): void { // $rectorConfig->import(LevelSetList::UP_TO_PHP_82); $rectorConfig->import(LaravelSetList::LARAVEL_100); }; - diff --git a/resources/views/layouts/eatvio.blade.php b/resources/views/layouts/eatvio.blade.php index 7607490..06c4f58 100644 --- a/resources/views/layouts/eatvio.blade.php +++ b/resources/views/layouts/eatvio.blade.php @@ -5,19 +5,22 @@ $curUrl = url()->current(); $isDiary = Str::of($curUrl)->test('/\/diary/'); @endphp + - - - + + + - @yield('page_title', 'Consult') - - - - - - - + @yield('page_title', 'Consult') + + + + + + + {{-- @livewireStyles --}} @@ -25,9 +28,10 @@ $isDiary = Str::of($curUrl)->test('/\/diary/'); + -@include('svg_parts.main') + @include('svg_parts.main')
+ @auth avatar + @endauth @@ -107,26 +116,26 @@ $isDiary = Str::of($curUrl)->test('/\/diary/');
@yield('main_section', '')
- + {{-- --}} {{-- --}} @stack('jq_scripts') @@ -141,5 +150,5 @@ $isDiary = Str::of($curUrl)->test('/\/diary/'); @livewire('wire-elements-modal') - + diff --git a/resources/views/livewire/plan/accordion.blade.php b/resources/views/livewire/plan/accordion.blade.php index 25dbde2..bdb7301 100644 --- a/resources/views/livewire/plan/accordion.blade.php +++ b/resources/views/livewire/plan/accordion.blade.php @@ -10,25 +10,27 @@ {{ $options1['short'] ?? '' }} -
!$accordionState['options1'], 'display: block' => $accordionState['options1']])> -
- {{ $options1['description'] ?? '' }} -
+ @if ($accordionState['options1']) +
+
+ {{ $options1['description'] ?? '' }} +
- @isset($options1['items']) - @foreach ($options1['items'] as $item) -
    -
  • - {{ $item }} - - {{-- - --}} -
  • -
- @endforeach - @endisset - -
+ @isset($options1['items']) + @foreach ($options1['items'] as $item) +
    +
  • + {{ $item }} + + {{-- - --}} +
  • +
+ @endforeach + @endisset + +
+ @endif
@if ($plan->packets_count == 3) @@ -43,26 +45,28 @@ {{ $options2['short'] ?? '' }} -
!$accordionState['options2'], 'display: block' => $accordionState['options2']])> -
- {{ $options2['description'] ?? '' }} -
+ @if ($accordionState['options2']) +
+
+ {{ $options2['description'] ?? '' }} +
- @isset($options2['items']) - @foreach ($options2['items'] as $item) -
    -
  • - {{ $item }} - - {{-- - --}} -
  • -
- @endforeach - @endisset - -
+ @isset($options2['items']) + @foreach ($options2['items'] as $item) +
    +
  • + {{ $item }} + + {{-- - --}} +
  • +
+ @endforeach + @endisset + +
+ @endif
@@ -76,26 +80,28 @@ {{ $options3['short'] ?? '' }} -
!$accordionState['options3'], 'display: block' => $accordionState['options3']])> -
- {{ $options3['description'] ?? '' }} -
+ @if ($accordionState['options3']) +
+
+ {{ $options3['description'] ?? '' }} +
- @isset($options3['items']) - @foreach ($options3['items'] as $item) -
    -
  • - {{ $item }} - - {{-- - --}} -
  • -
- @endforeach - @endisset - -
+ @isset($options3['items']) + @foreach ($options3['items'] as $item) +
    +
  • + {{ $item }} + + {{-- - --}} +
  • +
+ @endforeach + @endisset + +
+ @endif
@endif diff --git a/resources/views/livewire/plan/comment/show.blade.php b/resources/views/livewire/plan/comment/show.blade.php index 504e478..c630e63 100644 --- a/resources/views/livewire/plan/comment/show.blade.php +++ b/resources/views/livewire/plan/comment/show.blade.php @@ -1,90 +1,81 @@
@php - $positivComments = $plan->positiveComments(); + $positivComments = $plan->positiveComments(); - $negativeComments = $plan->negativeComments(); + $negativeComments = $plan->negativeComments(); - $positiveCommmentsCount = $positivComments->count(); + $positiveCommmentsCount = $positivComments->count(); - $negativeCommentsCount = $negativeComments->count(); + $negativeCommentsCount = $negativeComments->count(); @endphp
- - + +
-
$tabpanelState['negative'] - ]) role="tabpanel" id="tabpanel-1" tabindex="0" aria-labelledby="tab-1"> +
$tabpanelState['negative'] + ]) role="tabpanel" id="tabpanel-1" tabindex="0" aria-labelledby="tab-1"> +
@foreach ($positivComments->get() as $comment) -
-
-
- user +
+
+ user +
+
+
+ {{ $comment->author->name }}
-
-
- {{ $comment->author->name }} -
-
- {{ $comment->body }} -
+
+ {{ $comment->body }} +
+
+
+
+ {{ $plan->name }}
-
-
- {{ $plan->name }} -
-
- {{ $comment->grade }} -
- +
+ {{ $comment->grade }}
+
- @endforeach + @endforeach +
-
$tabpanelState['positive'] - ]) role="tabpanel" id="tabpanel-2" tabindex="0" aria-labelledby="tab-1"> +
$tabpanelState['positive'] + ]) role="tabpanel" id="tabpanel-2" tabindex="0" aria-labelledby="tab-1"> + +
@foreach ($negativeComments->get() as $comment) -
-
-
- user +
+
+ user +
+
+
+ {{ $comment->author->name }}
-
-
- {{ $comment->author->name }} -
-
- {{ $comment->body }} -
+
+ {{ $comment->body }} +
+
+
+
+ {{ $plan->name }}
-
-
- {{ $plan->name }} -
-
- {{ $comment->grade }} -
- - +
+ {{ $comment->grade }}
+
- @endforeach + @endforeach +
-
-
diff --git a/resources/views/livewire/plan/create.blade.php b/resources/views/livewire/plan/create.blade.php index bcc67ef..dfa0c1f 100644 --- a/resources/views/livewire/plan/create.blade.php +++ b/resources/views/livewire/plan/create.blade.php @@ -25,8 +25,7 @@ Изображение
diff --git a/resources/views/livewire/recipe/edit.blade.php b/resources/views/livewire/recipe/edit.blade.php index 32779d3..e94d903 100644 --- a/resources/views/livewire/recipe/edit.blade.php +++ b/resources/views/livewire/recipe/edit.blade.php @@ -36,8 +36,7 @@ @if (is_null($image)) formats @else - + step @endif @@ -310,6 +309,7 @@
+ + diff --git a/resources/views/livewire/recipe/tags-view.blade.php b/resources/views/livewire/recipe/tags-view.blade.php new file mode 100644 index 0000000..1c46c8c --- /dev/null +++ b/resources/views/livewire/recipe/tags-view.blade.php @@ -0,0 +1,62 @@ + diff --git a/resources/views/plan/show.blade.php b/resources/views/plan/show.blade.php index ae0b04e..15fdc5c 100644 --- a/resources/views/plan/show.blade.php +++ b/resources/views/plan/show.blade.php @@ -10,7 +10,7 @@ ->unique() ->count(); -$isPlanUrlActive= true; + $isPlanNavigationUrlActive = true; @endphp @section('main_section')
@@ -18,14 +18,16 @@ $isPlanUrlActive= true;
- + Планы питания консультанта
@@ -62,13 +64,48 @@ $isPlanUrlActive= true;
- {{-- --}} +
+
+
+
+ Время прохождения плана: +
+
+ {{ $plan->duration }} дней +
+
+
+
+ Проходят план: +
+
+ 2 пользователя +
+
+
+ + @livewire('plan.like.announcement-details', ['plan' => $plan]) +
+ +

+ {!! $plan->details !!} +

+ + @php + $planTypeSvgClasses = ['slim' => '#SlimBig', 'fit' => '#FitBig', 'wellness' => '#WellnessBig', 'behavior' => '#BehaviorBig']; + @endphp +
+ @foreach ($planTypeSvgClasses as $type => $svgCssClass) + @if (isset($plan->type[$type]) && $plan->type[$type] === true) + + + + @endif + @endforeach +
+ + + @livewire('plan.like.announcement-footer', ['plan' => $plan])
@livewire('plan.accordion', ['plan' => $plan]) @@ -79,22 +116,16 @@ $isPlanUrlActive= true;
-
+

ОТЗЫВЫ

@livewire('plan.comment.show', ['plan' => $plan]) - @livewire('plan.comment.create', ['plan' => $plan, 'user' => Auth::user()]) + @auth + @livewire('plan.comment.create', ['plan' => $plan, 'user' => Auth::user()]) + @endauth
- -
@endsection - -{{-- @push('jq_scripts') --}} -{{-- --}} -{{-- --}} -{{-- --}} -{{-- @endpush --}} diff --git a/resources/views/recipe/edit_form.blade.php b/resources/views/recipe/edit_form.blade.php index 8ffb40d..1cfe628 100644 --- a/resources/views/recipe/edit_form.blade.php +++ b/resources/views/recipe/edit_form.blade.php @@ -1,6 +1,9 @@ @extends('layouts/eatvio') @section('page_title', 'Create Recipe') +@php +$isRecipeNavigationUrlActive = true; +@endphp @section('main_section') @isset($recipe) @livewire('recipe.edit', ['recipe' => $recipe]); diff --git a/resources/views/recipe/show.blade.php b/resources/views/recipe/show.blade.php index f3a48ad..7b2898b 100644 --- a/resources/views/recipe/show.blade.php +++ b/resources/views/recipe/show.blade.php @@ -5,6 +5,7 @@ $recipeViewsCount = views($recipe) ->unique() ->count(); + $isRecipeNavigationUrlActive = true; @endphp @section('main_section')
@@ -32,7 +33,7 @@ @empty($author->profile_photo_path) thumb @else - thumb + thumb @endempty
@@ -58,7 +59,8 @@
@@ -100,25 +99,28 @@ @endphp @if (mb_strlen($ingredient['name']) > 1)
  • {{ $ingredient['name'] }} - {{ $ingredient['portion'] }} - {{ __('recipe.' . $localizedUnit) }}
  • + {{ __('recipe.' . $localizedUnit) }} + @endif @endforeach
    -
    -
    - ЦЕННОСТЬ: -
    -
      -
    • WIP
    • - {{-- + + {{--
      --}} + {{--
      --}} + {{-- ЦЕННОСТЬ: --}} + {{--
      --}} + {{--
        --}} + {{--
      • WIP
      • --}} + {{--
      • Калории: 139.9 ккал
      • Белки: 20.4 гр
      • Жиры: 5.7 гр
      • Углеводы: 1.8 гр
      • --}} -
      -
      + {{--
    --}} + {{--
    --}} +
    ЦЕННОСТЬ: @@ -135,9 +137,6 @@ Комментировать @livewire('recipe.like', ['recipe' => $recipe]) - {{-- --}} @@ -155,7 +154,7 @@
  • @if (isset($step['image']) && is_string($step['image']) && strlen($step['image']) > 4) - step + step @endif
    @@ -165,48 +164,20 @@
  • @endforeach - - {{--
  • -
    - step -
    -
    - Режем куриную грудку тонкими ломтиками. -
    -
  • -
  • -
    - step -
    -
    -

    - На край каждого кусочка филе кладем 1 ст. л. тертого сыра и порезанную зелень. -

    -

    - Формируем рулетик из куриного филе с сыром и зеленью, подворачивая с боков, чтобы сыр при приготовлении не вытек. Скрепляем края половинками зубочисток. -

    -
    -
  • --}}
    -
    +

    ОТЗЫВЫ

    @livewire('recipe.comment.show', ['recipe' => $recipe]) - @livewire('recipe.comment.create', ['recipe' => $recipe, 'user' => Auth::user()]) + @auth + @livewire('recipe.comment.create', ['recipe' => $recipe, 'user' => Auth::user()]) + @endauth
    - -
    - - @endsection -{{-- @push('jq_scripts') --}} -{{-- --}} -{{-- --}} -{{-- @endpush --}} diff --git a/resources/views/user/show.blade.php b/resources/views/user/show.blade.php index 79429cc..c0f830f 100644 --- a/resources/views/user/show.blade.php +++ b/resources/views/user/show.blade.php @@ -29,6 +29,10 @@ {{ __('profile.settings') }} +
    + @csrf + +
    @endif
    diff --git a/routes/fortify.php b/routes/fortify.php index cd79898..a93ef3f 100644 --- a/routes/fortify.php +++ b/routes/fortify.php @@ -105,80 +105,145 @@ Route::group( // Profile Information... if (Features::enabled(Features::updateProfileInformation())) { - Route::put('/user/profile-information', [ProfileInformationController::class, 'update']) - ->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')]) - ->name('user-profile-information.update'); + Route::put( + '/user/profile-information', + [ProfileInformationController::class, 'update'] + )->middleware( + [config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')] + )->name('user-profile-information.update'); } // Passwords... if (Features::enabled(Features::updatePasswords())) { - Route::put('/user/password', [PasswordController::class, 'update']) - ->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')]) - ->name('user-password.update'); + Route::put( + '/user/password', + [PasswordController::class, 'update'] + )->middleware( + [ + config( + 'fortify.auth_middleware', + 'auth' + ) + .':' + .config('fortify.guard'), + ] + )->name('user-password.update'); } // Password Confirmation... if ($enableViews) { - Route::get('/user/confirm-password', [ConfirmablePasswordController::class, 'show']) - ->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')]); + Route::get( + '/user/confirm-password', + [ConfirmablePasswordController::class, 'show'] + )->middleware( + [ + config( + 'fortify.auth_middleware', + 'auth' + ) + .':' + .config('fortify.guard'), + ] + ); } - Route::get('/user/confirmed-password-status', [ConfirmedPasswordStatusController::class, 'show']) - ->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')]) - ->name('password.confirmation'); + Route::get( + '/user/confirmed-password-status', + [ConfirmedPasswordStatusController::class, 'show'] + )->middleware( + [ + config( + 'fortify.auth_middleware', + 'auth' + ) + .':' + .config('fortify.guard'), + ] + )->name('password.confirmation'); - Route::post('/user/confirm-password', [ConfirmablePasswordController::class, 'store']) - ->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')]) - ->name('password.confirm'); + Route::post( + '/user/confirm-password', + [ConfirmablePasswordController::class, 'store'] + )->middleware( + [ + config('fortify.auth_middleware', 'auth') + .':' + .config('fortify.guard'), + ] + )->name('password.confirm'); // Two Factor Authentication... if (Features::enabled(Features::twoFactorAuthentication())) { if ($enableViews) { - Route::get('/two-factor-challenge', [TwoFactorAuthenticatedSessionController::class, 'create']) - ->middleware(['guest:'.config('fortify.guard')]) - ->name('two-factor.login'); + Route::get( + '/two-factor-challenge', + [TwoFactorAuthenticatedSessionController::class, 'create'] + )->middleware( + ['guest:'.config('fortify.guard')] + )->name('two-factor.login'); } - Route::post('/two-factor-challenge', [TwoFactorAuthenticatedSessionController::class, 'store']) - ->middleware( - array_filter( - [ - 'guest:'.config('fortify.guard'), - $twoFactorLimiter ? 'throttle:'.$twoFactorLimiter : null, - ] - ) - ); + Route::post( + '/two-factor-challenge', + [TwoFactorAuthenticatedSessionController::class, 'store'] + )->middleware( + array_filter( + [ + 'guest:'.config('fortify.guard'), + $twoFactorLimiter + ? 'throttle:'.$twoFactorLimiter + : null, + ] + ) + ); - $twoFactorMiddleware = Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword') + $twoFactorMiddleware = Features::optionEnabled( + Features::twoFactorAuthentication(), + 'confirmPassword' + ) ? [config('fortify.auth_middleware', 'auth').':'.config('fortify.guard'), 'password.confirm'] : [config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')]; - Route::post('/user/two-factor-authentication', [TwoFactorAuthenticationController::class, 'store']) - ->middleware($twoFactorMiddleware) + Route::post( + '/user/two-factor-authentication', + [TwoFactorAuthenticationController::class, 'store'] + )->middleware($twoFactorMiddleware) ->name('two-factor.enable'); - Route::post('/user/confirmed-two-factor-authentication', [ConfirmedTwoFactorAuthenticationController::class, 'store']) - ->middleware($twoFactorMiddleware) + Route::post( + '/user/confirmed-two-factor-authentication', + [ConfirmedTwoFactorAuthenticationController::class, 'store'] + )->middleware($twoFactorMiddleware) ->name('two-factor.confirm'); - Route::delete('/user/two-factor-authentication', [TwoFactorAuthenticationController::class, 'destroy']) - ->middleware($twoFactorMiddleware) + Route::delete( + '/user/two-factor-authentication', + [TwoFactorAuthenticationController::class, 'destroy'] + )->middleware($twoFactorMiddleware) ->name('two-factor.disable'); - Route::get('/user/two-factor-qr-code', [TwoFactorQrCodeController::class, 'show']) - ->middleware($twoFactorMiddleware) + Route::get( + '/user/two-factor-qr-code', + [TwoFactorQrCodeController::class, 'show'] + )->middleware($twoFactorMiddleware) ->name('two-factor.qr-code'); - Route::get('/user/two-factor-secret-key', [TwoFactorSecretKeyController::class, 'show']) - ->middleware($twoFactorMiddleware) + Route::get( + '/user/two-factor-secret-key', + [TwoFactorSecretKeyController::class, 'show'] + )->middleware($twoFactorMiddleware) ->name('two-factor.secret-key'); - Route::get('/user/two-factor-recovery-codes', [RecoveryCodeController::class, 'index']) - ->middleware($twoFactorMiddleware) + Route::get( + '/user/two-factor-recovery-codes', + [RecoveryCodeController::class, 'index'] + )->middleware($twoFactorMiddleware) ->name('two-factor.recovery-codes'); - Route::post('/user/two-factor-recovery-codes', [RecoveryCodeController::class, 'store']) - ->middleware($twoFactorMiddleware); + Route::post( + '/user/two-factor-recovery-codes', + [RecoveryCodeController::class, 'store'] + )->middleware($twoFactorMiddleware); } } ); diff --git a/routes/jetstream.php b/routes/jetstream.php index e2e95a2..6588e64 100644 --- a/routes/jetstream.php +++ b/routes/jetstream.php @@ -17,8 +17,14 @@ Route::group( ], function () { if (Jetstream::hasTermsAndPrivacyPolicyFeature()) { - Route::get('/terms-of-service', [TermsOfServiceController::class, 'show'])->name('terms.show'); - Route::get('/privacy-policy', [PrivacyPolicyController::class, 'show'])->name('policy.show'); + Route::get( + '/terms-of-service', + [TermsOfServiceController::class, 'show'] + )->name('terms.show'); + Route::get( + '/privacy-policy', + [PrivacyPolicyController::class, 'show'] + )->name('policy.show'); } $authMiddleware = config('jetstream.guard') @@ -30,27 +36,50 @@ Route::group( : null; Route::group( - ['middleware' => array_values(array_filter([$authMiddleware, $authSessionMiddleware]))], + [ + 'middleware' => array_values( + array_filter( + [$authMiddleware, $authSessionMiddleware] + ) + ), + ], function () { // User & Profile... - Route::get('/user/profile', [UserProfileController::class, 'show'])->name('uprofile.show'); + Route::get( + '/user/profile', + [UserProfileController::class, 'show'] + )->name('uprofile.show'); Route::group( ['middleware' => 'verified'], function () { // API... if (Jetstream::hasApiFeatures()) { - Route::get('/user/api-tokens', [ApiTokenController::class, 'index'])->name('api-tokens.index'); + Route::get( + '/user/api-tokens', + [ApiTokenController::class, 'index'] + )->name('api-tokens.index'); } // Teams... if (Jetstream::hasTeamFeatures()) { - Route::get('/teams/create', [TeamController::class, 'create'])->name('teams.create'); - Route::get('/teams/{team}', [TeamController::class, 'show'])->name('teams.show'); - Route::put('/current-team', [CurrentTeamController::class, 'update'])->name('current-team.update'); + Route::get( + '/teams/create', + [TeamController::class, 'create'] + )->name('teams.create'); + Route::get( + '/teams/{team}', + [TeamController::class, 'show'] + )->name('teams.show'); + Route::put( + '/current-team', + [CurrentTeamController::class, 'update'] + )->name('current-team.update'); - Route::get('/team-invitations/{invitation}', [TeamInvitationController::class, 'accept']) - ->middleware(['signed']) + Route::get( + '/team-invitations/{invitation}', + [TeamInvitationController::class, 'accept'] + )->middleware(['signed']) ->name('team-invitations.accept'); } } diff --git a/routes/web.php b/routes/web.php index b135594..17f78ac 100644 --- a/routes/web.php +++ b/routes/web.php @@ -65,7 +65,20 @@ Route::group( [RegistrationStartController::class, 'start'] )->name('register.start'); - Route::get('/registration/{step}', Registration\Step1::class)->name('register.step1'); + Route::get( + '/registration/{step}', + Registration\Step1::class + )->name('register.step1'); + + Route::get( + '/plan/', + [PlanController::class, 'index'] + )->name('plan.index'); + + Route::get( + '/recipe/', + [RecipeController::class, 'index'] + )->name('recipe.index'); Route::middleware( [ @@ -81,33 +94,100 @@ Route::group( return view('dashboard'); } )->name('dashboard'); - Route::resource('profile', ProfileController::class)->parameters(['profile' => 'user']); - Route::get('/feed', [FeedController::class, 'index'])->name('news_feed'); - Route::resource('chat', ChatController::class)->only(['index', 'create', 'show']); - Route::resource('diary', DiaryController::class); - Route::resource('calendar', CalendarController::class); - Route::resource('user_detailz', UserDetailzController::class); - Route::resource('user', UserController::class)->only('show'); - Route::resource('finance', FinanceController::class)->only(['index', 'show']); - Route::resource('plan', PlanController::class)->only(['create', 'show', 'index', 'edit']); - Route::resource('diet', DietController::class)->only(['create', 'show', 'index', 'edit']); - Route::resource('consultants', ConsultantController::class)->only(['index']); - Route::resource('recipe', RecipeController::class)->only(['create', 'show', 'index', 'edit']); - Route::resource('blog_post', BlogPostController::class)->only(['create', 'show', 'index', 'edit']); - Route::resource('product_nutritional_value', ProductNutritionalValueController::class)->only(['create', 'show', 'index', 'edit']); - Route::resource('consultant_request', ConsultantRequestFormController::class) + Route::resource( + 'profile', + ProfileController::class + )->parameters(['profile' => 'user']); + Route::get( + '/feed', + [FeedController::class, 'index'] + )->name('news_feed'); + Route::resource( + 'chat', + ChatController::class + )->only(['index', 'create', 'show']); + + Route::resource( + 'diary', + DiaryController::class + ); + + Route::resource( + 'calendar', + CalendarController::class + ); + + Route::resource( + 'user_detailz', + UserDetailzController::class + ); + + Route::resource( + 'user', + UserController::class + )->only('show'); + + Route::resource( + 'finance', + FinanceController::class + )->only(['index', 'show']); + + Route::resource( + 'plan', + PlanController::class + )->only(['create', 'edit']); + + Route::resource( + 'diet', + DietController::class + )->only(['create', 'show', 'index', 'edit']); + + Route::resource( + 'consultants', + ConsultantController::class + )->only(['index']); + + Route::resource( + 'recipe', + RecipeController::class + )->only(['create', 'edit']); + + Route::resource( + 'blog_post', + BlogPostController::class + )->only(['create', 'show', 'index', 'edit']); + + Route::resource( + 'product_nutritional_value', + ProductNutritionalValueController::class + )->only(['create', 'show', 'index', 'edit']); + + Route::resource( + 'consultant_request', + ConsultantRequestFormController::class + ) ->parameters( [ 'consultant_request' => 'user', ] ); - Route::resource('consultant_diary_comment', ConsultantDiaryCommentController::class) - ->parameters( - [ - 'consultant_diary_comment' => 'diary', - ] - ); + + Route::resource( + 'consultant_diary_comment', + ConsultantDiaryCommentController::class + ) + ->parameters(['consultant_diary_comment' => 'diary']); } ); + + Route::get( + '/plan/{plan}', + [PlanController::class, 'show'] + )->name('plan.show'); + + Route::get( + '/recipe/{recipe}', + [RecipeController::class, 'show'] + )->name('recipe.show'); } ); diff --git a/tests/Feature/ApiTokenPermissionsTest.php b/tests/Feature/ApiTokenPermissionsTest.php index b16b54d..bc2fcce 100644 --- a/tests/Feature/ApiTokenPermissionsTest.php +++ b/tests/Feature/ApiTokenPermissionsTest.php @@ -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()); diff --git a/tests/Feature/BlogPost/CreateTest.php b/tests/Feature/BlogPost/CreateTest.php new file mode 100644 index 0000000..da7e846 --- /dev/null +++ b/tests/Feature/BlogPost/CreateTest.php @@ -0,0 +1,180 @@ +refreshApplicationWithLocale('en'); + + Storage::fake('tmp-for-tests'); + $this->image = UploadedFile::fake()->image('blogPost.png'); + + $this->user = User::factory()->create(['is_consultant' => true]); + $this->blogPost = BlogPost::factory()->make(); + + } + + public function test_show_form_create_blogPost(): void + { + $response = $this + ->actingAs($this->user) + ->get(route('blog_post.create')); + + $response->assertSuccessful(); + } + + public function test_publish_new_blogPost_success(): void + { + $this->actingAs($this->user); + + $blogPostCountAtStart = BlogPost::count(); + + $testCase = Livewire::test(Create::class) + ->set('title', $this->blogPost->title) + ->assertSet('title', $this->blogPost->title) + ->set('state', $this->blogPost->state) + ->assertSet('state', $this->blogPost->state) + ->set('image', $this->image) + ->set('description', $this->blogPost->description) + ->assertSet('description', $this->blogPost->description) + ->set('youtube_url', $this->blogPost->youtube_url) + ->assertSet('youtube_url', $this->blogPost->youtube_url) + ->call('publish') + ->assertSuccessful() + ->assertHasNoErrors(['title', 'description', 'youtube_url']); + + + $lastCreatedBlogPost = BlogPost::orderBy('id', 'desc')->first(); + + $newBlogPostUrl = route('blog_post.show', $lastCreatedBlogPost); + + $testCase->assertRedirect($newBlogPostUrl); + + Storage::disk('tmp-for-tests')->assertExists($lastCreatedBlogPost->image); + + $this->assertEquals($blogPostCountAtStart + 1, BlogPost::count()); + + $response = $this->actingAs($this->user)->get(route('blog_post.index')); + + $response->assertSuccessful(); + } + + public function test_to_draft_new_blogPost_success(): void + { + $this->actingAs($this->user); + + $blogPostCountAtStart = BlogPost::count(); + + $testCase = Livewire::test(Create::class) + ->set('title', $this->blogPost->title) + ->assertSet('title', $this->blogPost->title) + ->set('state', $this->blogPost->state) + ->assertSet('state', $this->blogPost->state) + ->set('image', $this->image) + ->set('description', $this->blogPost->description) + ->assertSet('description', $this->blogPost->description) + ->set('youtube_url', $this->blogPost->youtube_url) + ->assertSet('youtube_url', $this->blogPost->youtube_url) + ->call('draft') + ->assertSuccessful() + ->assertHasNoErrors(['title', 'description', 'youtube_url']); + + + self::assertEquals('archived', $testCase->state); + + $lastCreatedBlogPost = BlogPost::orderBy('id', 'desc')->first(); + + $newBlogPostUrl = route('blog_post.show', $lastCreatedBlogPost); + + $testCase->assertRedirect($newBlogPostUrl); + + Storage::disk('tmp-for-tests')->assertExists($lastCreatedBlogPost->image); + + $this->assertEquals($blogPostCountAtStart + 1, BlogPost::count()); + + $response = $this->actingAs($this->user)->get(route('blog_post.index')); + + $response->assertSuccessful(); + } + + public function test_to_preview_new_blogPost_success(): void + { + $this->actingAs($this->user); + + $blogPostCountAtStart = BlogPost::count(); + + $testCase = Livewire::test(Create::class) + ->set('title', $this->blogPost->title) + ->assertSet('title', $this->blogPost->title) + ->set('state', $this->blogPost->state) + ->assertSet('state', $this->blogPost->state) + ->set('image', $this->image) + ->set('description', $this->blogPost->description) + ->assertSet('description', $this->blogPost->description) + ->set('youtube_url', $this->blogPost->youtube_url) + ->assertSet('youtube_url', $this->blogPost->youtube_url) + ->call('preview') + ->assertSuccessful() + ->assertHasNoErrors(['title', 'description', 'youtube_url']); + + + self::assertEquals('archived', $testCase->state); + + $lastCreatedBlogPost = BlogPost::orderBy('id', 'desc')->first(); + + $newBlogPostUrl = route('blog_post.show', $lastCreatedBlogPost); + + $testCase->assertRedirect($newBlogPostUrl); + + Storage::disk('tmp-for-tests')->assertExists($lastCreatedBlogPost->image); + + $this->assertEquals($blogPostCountAtStart + 1, BlogPost::count()); + + $response = $this->actingAs($this->user)->get(route('blog_post.index')); + + $response->assertSuccessful(); + } + + public function test_set_empty_data(): void + { + $this->actingAs($this->user); + + $blogPostCountAtStart = BlogPost::count(); + + Livewire::test(Create::class) + ->set('title', null) + ->assertSet('title', null) + ->set('state', null) + ->assertSet('state', null) + ->set('image', null) + ->set('description', null) + ->assertSet('description', null) + ->set('youtube_url', null) + ->assertSet('youtube_url', null) + ->call('publish') + ->assertSuccessful() + ->assertHasErrors(['image', 'description']); + + $this->assertEquals($blogPostCountAtStart, BlogPost::count()); + } +} diff --git a/tests/Feature/BlogPost/EditTest.php b/tests/Feature/BlogPost/EditTest.php new file mode 100644 index 0000000..ec8520c --- /dev/null +++ b/tests/Feature/BlogPost/EditTest.php @@ -0,0 +1,195 @@ +refreshApplicationWithLocale('en'); + + Storage::fake('tmp-for-tests'); + $this->image = UploadedFile::fake()->image('blogPost.png'); + + $this->user = User::factory()->create(['is_consultant' => true]); + $this->blogPost = BlogPost::factory()->create(); + } + + public function test_show_form_edit_blogPost(): void + { + $response = $this + ->actingAs($this->user) + ->get(route('blog_post.edit', $this->blogPost)); + + $response->assertSuccessful(); + } + + public function test_publish_new_blogPost_success(): void + { + $this->actingAs($this->user); + + $updatedBlogPostBeforeToAddDatabase = BlogPost::factory()->make(); + + $testCase = Livewire::test( + Edit::class, [ + 'blogPost' => $this->blogPost, + ] + ) + ->set('title', $updatedBlogPostBeforeToAddDatabase->title) + ->assertSet('title', $updatedBlogPostBeforeToAddDatabase->title) + ->set('state', $updatedBlogPostBeforeToAddDatabase->state) + ->assertSet('state', $updatedBlogPostBeforeToAddDatabase->state) + ->set('image', $this->image) + ->set('description', $updatedBlogPostBeforeToAddDatabase->description) + ->assertSet('description', $updatedBlogPostBeforeToAddDatabase->description) + ->set('youtube_url', $updatedBlogPostBeforeToAddDatabase->youtube_url) + ->assertSet('youtube_url', $updatedBlogPostBeforeToAddDatabase->youtube_url) + ->call('publish') + ->assertSuccessful() + ->assertHasNoErrors(['title', 'state', 'description', 'youtube_url']); + + + $updatedBlogPostAfterToAddDatabase = BlogPost::orderByDesc('id')->first(); + + $newBlogPostUrl = route('blog_post.show', $updatedBlogPostAfterToAddDatabase); + + Storage::disk('tmp-for-tests')->assertExists($updatedBlogPostAfterToAddDatabase->image); + + + // check data after update recipe + self::assertEquals($updatedBlogPostBeforeToAddDatabase->title, $updatedBlogPostAfterToAddDatabase->title); + self::assertEquals($updatedBlogPostBeforeToAddDatabase->state, $updatedBlogPostAfterToAddDatabase->state); + self::assertEquals($updatedBlogPostBeforeToAddDatabase->description, $updatedBlogPostAfterToAddDatabase->description); + // self::assertEquals($updatedBlogPostBeforeToAddDatabase->youtube_url, $updatedBlogPostAfterToAddDatabase->youtube_url); + + $testCase->assertRedirect($newBlogPostUrl); + } + + public function test_to_draft_new_blogPost_success(): void + { + $this->actingAs($this->user); + + $updatedBlogPostBeforeToAddDatabase = BlogPost::factory()->make(); + + $testCase = Livewire::test( + Edit::class, [ + 'blogPost' => $this->blogPost, + ] + ) + ->set('title', $updatedBlogPostBeforeToAddDatabase->title) + ->assertSet('title', $updatedBlogPostBeforeToAddDatabase->title) + ->set('state', $updatedBlogPostBeforeToAddDatabase->state) + ->assertSet('state', $updatedBlogPostBeforeToAddDatabase->state) + ->set('image', $this->image) + ->set('description', $updatedBlogPostBeforeToAddDatabase->description) + ->assertSet('description', $updatedBlogPostBeforeToAddDatabase->description) + ->set('youtube_url', $updatedBlogPostBeforeToAddDatabase->youtube_url) + ->assertSet('youtube_url', $updatedBlogPostBeforeToAddDatabase->youtube_url) + ->call('draft') + ->assertSuccessful() + ->assertHasNoErrors(['title', 'state', 'description', 'youtube_url']); + + + $updatedBlogPostAfterToAddDatabase = BlogPost::orderByDesc('id')->first(); + + $newBlogPostUrl = route('blog_post.show', $updatedBlogPostAfterToAddDatabase); + + Storage::disk('tmp-for-tests')->assertExists($updatedBlogPostAfterToAddDatabase->image); + + + // check data after update recipe + self::assertEquals($updatedBlogPostBeforeToAddDatabase->title, $updatedBlogPostAfterToAddDatabase->title); + self::assertEquals('archived', $updatedBlogPostAfterToAddDatabase->state); + self::assertEquals($updatedBlogPostBeforeToAddDatabase->description, $updatedBlogPostAfterToAddDatabase->description); + // self::assertEquals($updatedBlogPostBeforeToAddDatabase->youtube_url, $updatedBlogPostAfterToAddDatabase->youtube_url); + + $testCase->assertRedirect($newBlogPostUrl); + } + + public function test_to_preview_new_blogPost_success(): void + { + $this->actingAs($this->user); + + $updatedBlogPostBeforeToAddDatabase = BlogPost::factory()->make(); + + $testCase = Livewire::test( + Edit::class, [ + 'blogPost' => $this->blogPost, + ] + ) + ->set('title', $updatedBlogPostBeforeToAddDatabase->title) + ->assertSet('title', $updatedBlogPostBeforeToAddDatabase->title) + ->set('state', $updatedBlogPostBeforeToAddDatabase->state) + ->assertSet('state', $updatedBlogPostBeforeToAddDatabase->state) + ->set('image', $this->image) + ->set('description', $updatedBlogPostBeforeToAddDatabase->description) + ->assertSet('description', $updatedBlogPostBeforeToAddDatabase->description) + ->set('youtube_url', $updatedBlogPostBeforeToAddDatabase->youtube_url) + ->assertSet('youtube_url', $updatedBlogPostBeforeToAddDatabase->youtube_url) + ->call('preview') + ->assertSuccessful() + ->assertHasNoErrors(['title', 'state', 'description', 'youtube_url']); + + + $updatedBlogPostAfterToAddDatabase = BlogPost::orderByDesc('id')->first(); + + $newBlogPostUrl = route('blog_post.show', $updatedBlogPostAfterToAddDatabase); + + Storage::disk('tmp-for-tests')->assertExists($updatedBlogPostAfterToAddDatabase->image); + + + // check data after update recipe + self::assertEquals($updatedBlogPostBeforeToAddDatabase->title, $updatedBlogPostAfterToAddDatabase->title); + self::assertEquals('archived', $updatedBlogPostAfterToAddDatabase->state); + self::assertEquals($updatedBlogPostBeforeToAddDatabase->description, $updatedBlogPostAfterToAddDatabase->description); + // self::assertEquals($updatedBlogPostBeforeToAddDatabase->youtube_url, $updatedBlogPostAfterToAddDatabase->youtube_url); + + $testCase->assertRedirect($newBlogPostUrl); + + } + + public function testNothingChange(): void + { + $this->actingAs($this->user); + + $blogPostUpdate = Livewire::test( + Edit::class, [ + 'blogPost' => $this->blogPost, + ] + ) + ->call('publish') + ->assertSuccessful() + ->assertHasNoErrors(['title', 'state', 'description', 'youtube_url']); + + $newBlogPostUrl = route('blog_post.show', $this->blogPost, false); + + Storage::disk('tmp-for-tests')->assertMissing($blogPostUpdate->image); + + // check data after update recipe + self::assertEquals($this->blogPost->title, $blogPostUpdate->title); + self::assertEquals($this->blogPost->state, $blogPostUpdate->state); + self::assertEquals($this->blogPost->description, $blogPostUpdate->description); + // self::assertEquals($this->blogPost->youtube_url, $blogPostUpdate->youtube_url); + + $blogPostUpdate->assertRedirect($newBlogPostUrl); + } + +} + diff --git a/tests/Feature/BlogPost/IndexTest.php b/tests/Feature/BlogPost/IndexTest.php new file mode 100644 index 0000000..c12d432 --- /dev/null +++ b/tests/Feature/BlogPost/IndexTest.php @@ -0,0 +1,31 @@ +refreshApplicationWithLocale('en'); + + $this->user = User::factory()->create(['is_consultant' => true]); + } + + public function test_index_page_success(): void + { + $response = $this + ->actingAs($this->user) + ->get(route('blog_post.index')); + + $response + ->assertOk(); + } +} diff --git a/tests/Feature/BlogPost/ShowTest.php b/tests/Feature/BlogPost/ShowTest.php new file mode 100644 index 0000000..67a16be --- /dev/null +++ b/tests/Feature/BlogPost/ShowTest.php @@ -0,0 +1,35 @@ +refreshApplicationWithLocale('en'); + + $this->user = User::inRandomOrder()->first(); + $this->blogPost = BlogPost::inRandomOrder()->first(); + } + + public function test_show_page_success(): void + { + $response = $this->actingAs($this->user) + ->get(route('blog_post.show', $this->blogPost)); + + $response + ->assertOk(); + } + +} diff --git a/tests/Feature/CreateApiTokenTest.php b/tests/Feature/CreateApiTokenTest.php index 744ed90..fab69d9 100644 --- a/tests/Feature/CreateApiTokenTest.php +++ b/tests/Feature/CreateApiTokenTest.php @@ -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()); diff --git a/tests/Feature/DeleteAccountTest.php b/tests/Feature/DeleteAccountTest.php index bcaf59f..2fc7d06 100644 --- a/tests/Feature/DeleteAccountTest.php +++ b/tests/Feature/DeleteAccountTest.php @@ -17,13 +17,11 @@ class DeleteAccountTest extends TestCase { if (! Features::hasAccountDeletionFeatures()) { $this->markTestSkipped('Account deletion is not enabled.'); - - return; } $this->actingAs($user = User::factory()->create()); - $component = Livewire::test(DeleteUserForm::class) + Livewire::test(DeleteUserForm::class) ->set('password', 'password') ->call('deleteUser'); @@ -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()); diff --git a/tests/Feature/DeleteApiTokenTest.php b/tests/Feature/DeleteApiTokenTest.php index 6ed0861..1812e43 100644 --- a/tests/Feature/DeleteApiTokenTest.php +++ b/tests/Feature/DeleteApiTokenTest.php @@ -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), diff --git a/tests/Feature/Diet/CreateTest.php b/tests/Feature/Diet/CreateTest.php new file mode 100644 index 0000000..2ecd4db --- /dev/null +++ b/tests/Feature/Diet/CreateTest.php @@ -0,0 +1,185 @@ +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(); + + 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()); + } +} diff --git a/tests/Feature/Diet/EditTest.php b/tests/Feature/Diet/EditTest.php new file mode 100644 index 0000000..725ebfe --- /dev/null +++ b/tests/Feature/Diet/EditTest.php @@ -0,0 +1,204 @@ +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); + } + +} + diff --git a/tests/Feature/Diet/IndexTest.php b/tests/Feature/Diet/IndexTest.php new file mode 100644 index 0000000..d7e6702 --- /dev/null +++ b/tests/Feature/Diet/IndexTest.php @@ -0,0 +1,31 @@ +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(); + } +} diff --git a/tests/Feature/Diet/ShowTest.php b/tests/Feature/Diet/ShowTest.php new file mode 100644 index 0000000..f16a855 --- /dev/null +++ b/tests/Feature/Diet/ShowTest.php @@ -0,0 +1,31 @@ +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(); + } +} diff --git a/tests/Feature/EmailVerificationTest.php b/tests/Feature/EmailVerificationTest.php index ad0257d..412b633 100644 --- a/tests/Feature/EmailVerificationTest.php +++ b/tests/Feature/EmailVerificationTest.php @@ -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(); diff --git a/tests/Feature/MealFormTest.php b/tests/Feature/MealFormTest.php index 97d538b..4bce386 100644 --- a/tests/Feature/MealFormTest.php +++ b/tests/Feature/MealFormTest.php @@ -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'); diff --git a/tests/Feature/PasswordResetTest.php b/tests/Feature/PasswordResetTest.php index 7c65edb..03d9c35 100644 --- a/tests/Feature/PasswordResetTest.php +++ b/tests/Feature/PasswordResetTest.php @@ -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,15 +28,13 @@ class PasswordResetTest extends TestCase { if (! Features::enabled(Features::resetPasswords())) { $this->markTestSkipped('Password updates are not enabled.'); - - return; } Notification::fake(); $user = User::factory()->create(); - $response = $this->post('/forgot-password', [ + $this->post('/forgot-password', [ 'email' => $user->email, ]); @@ -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(); diff --git a/tests/Feature/Plan/CreateTest.php b/tests/Feature/Plan/CreateTest.php index 34225b3..414c422 100644 --- a/tests/Feature/Plan/CreateTest.php +++ b/tests/Feature/Plan/CreateTest.php @@ -4,21 +4,21 @@ namespace Tests\Feature\Plan; use App\Livewire\Plan\Create; use App\Models\Plan; -// use Livewire\WithFileUploads; 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; class CreateTest extends TestCase { use RefreshDatabase; - private $image; + private File $image; - private $plan; + private Plan $plan; protected User $user; @@ -26,7 +26,7 @@ class CreateTest extends TestCase { $this->refreshApplicationWithLocale('en'); - Storage::fake('plans'); + Storage::fake('tmp-for-tests'); $this->image = UploadedFile::fake()->image('plan.png'); $this->user = User::factory()->create(['is_consultant' => true]); @@ -34,7 +34,7 @@ class CreateTest extends TestCase } - public function test_show_form_create_plan() + public function test_show_form_create_plan(): void { $response = $this ->actingAs($this->user) @@ -47,10 +47,9 @@ class CreateTest extends TestCase { $this->actingAs($this->user); - // $this->assertEquals($this->plan->count(), $count = Plan::count()); $planCountAtStart = Plan::count(); - Livewire::test(Create::class) + $testCase = Livewire::test(Create::class) ->set('name', $this->plan->name) ->assertSet('name', $this->plan->name) ->set('image', $this->image) @@ -74,15 +73,20 @@ class CreateTest extends TestCase ->assertSuccessful() ->assertHasNoErrors(['name', 'image', 'duration', 'details', 'packets_count', 'packet1_options', 'packet2_options', 'packet3_options']); - Storage::disk('public')->assertExists($this->plan->image); + + $lastCreatedPlan = Plan::orderBy('id', 'desc')->first(); + + $newPlanUrl = route('plan.show', $lastCreatedPlan); + + $testCase->assertRedirect($newPlanUrl); + + Storage::disk('tmp-for-tests')->assertExists($lastCreatedPlan->image); $this->assertEquals($planCountAtStart + 1, Plan::count()); $response = $this->actingAs($this->user)->get(route('plan.index')); $response->assertSuccessful(); - - // $this->assertEquals($count + 1, Plan::count()); } public function test_to_draft_new_plan_success(): void @@ -91,10 +95,7 @@ class CreateTest extends TestCase $planCountAtStart = Plan::count(); - // $planLastId = $this->plan->latest()->first()->id; - // $expectedRedirectRoute = route('plan.show', ['plan' => $planLastId + 1]); - - Livewire::test(Create::class) + $testCase = Livewire::test(Create::class) ->set('name', $this->plan->name) ->assertSet('name', $this->plan->name) ->set('image', $this->image) @@ -115,10 +116,17 @@ class CreateTest extends TestCase ->set('packet3_options', $this->plan->packet3_options) ->assertSet('packet3_options', $this->plan->packet3_options) ->call('addToDrafts') - ->assertRedirect() + ->assertSuccessful() ->assertHasNoErrors(['name', 'image', 'duration', 'details']); - Storage::disk('public')->assertExists($this->plan->image); + + $lastCreatedPlan = Plan::orderBy('id', 'desc')->first(); + $newPlanUrl = route('plan.show', $lastCreatedPlan); + + Storage::disk('tmp-for-tests')->assertExists($lastCreatedPlan->image); + + $testCase->assertRedirect($newPlanUrl); + $this->assertEquals($planCountAtStart + 1, Plan::count()); } @@ -129,7 +137,8 @@ class CreateTest extends TestCase $planCountAtStart = Plan::count(); - Livewire::test(Create::class) + + $testCase = Livewire::test(Create::class) ->set('name', $this->plan->name) ->assertSet('name', $this->plan->name) ->set('image', $this->image) @@ -153,7 +162,13 @@ class CreateTest extends TestCase ->assertSuccessful() ->assertHasNoErrors(['name', 'image', 'duration', 'details']); - Storage::disk('public')->assertExists($this->plan->image); + $lastCreatedPlan = Plan::orderBy('id', 'desc')->first(); + $newPlanUrl = route('plan.show', $lastCreatedPlan); + + Storage::disk('tmp-for-tests')->assertExists($lastCreatedPlan->image); + + $testCase->assertRedirect($newPlanUrl); + $this->assertEquals($planCountAtStart + 1, Plan::count()); } @@ -176,7 +191,7 @@ class CreateTest extends TestCase ->set('packet2_options', null) ->set('packet3_options', null) ->call('publish') - ->assertHasErrors(['name', 'image', 'duration', 'details']); + ->assertHasErrors(['name', 'image', 'details']); $this->assertEquals($planCountAtStart, Plan::count()); } diff --git a/tests/Feature/Plan/EditTest.php b/tests/Feature/Plan/EditTest.php new file mode 100644 index 0000000..e15121a --- /dev/null +++ b/tests/Feature/Plan/EditTest.php @@ -0,0 +1,232 @@ +refreshApplicationWithLocale('en'); + + Storage::fake('tmp-for-tests'); + $this->image = UploadedFile::fake()->image('plan.png'); + + $this->user = User::factory()->create(['is_consultant' => true]); + $this->plan = Plan::factory()->create(); + } + + public function test_show_form_edit_plan(): void + { + $response = $this + ->actingAs($this->user) + ->get(route('plan.edit', $this->plan)); + + $response->assertSuccessful(); + } + + public function test_publish_new_plan_success(): void + { + $this->actingAs($this->user); + + $updatedPlanBeforeToAddDatabase = Plan::factory()->make(); + + $testCase = Livewire::test(Edit::class, [ + 'plan' => $this->plan, + ]) + ->set('name', $updatedPlanBeforeToAddDatabase->name) + ->assertSet('name', $updatedPlanBeforeToAddDatabase->name) + ->set('image', $this->image) + ->set('duration', $updatedPlanBeforeToAddDatabase->duration) + ->assertSet('duration', $updatedPlanBeforeToAddDatabase->duration) + ->set('state', $updatedPlanBeforeToAddDatabase->state) + ->assertSet('state', $updatedPlanBeforeToAddDatabase->state) + ->set('type', $updatedPlanBeforeToAddDatabase->type) + ->assertSet('type', $updatedPlanBeforeToAddDatabase->type) + ->set('details', $updatedPlanBeforeToAddDatabase->details) + ->assertSet('details', $updatedPlanBeforeToAddDatabase->details) + ->set('packets_count', $updatedPlanBeforeToAddDatabase->packets_count) + ->assertSet('packets_count', $updatedPlanBeforeToAddDatabase->packets_count) + ->set('packet1_options', $updatedPlanBeforeToAddDatabase->packet1_options) + ->assertSet('packet1_options', $updatedPlanBeforeToAddDatabase->packet1_options) + ->set('packet2_options', $updatedPlanBeforeToAddDatabase->packet2_options) + ->assertSet('packet2_options', $updatedPlanBeforeToAddDatabase->packet2_options) + ->set('packet3_options', $updatedPlanBeforeToAddDatabase->packet3_options) + ->assertSet('packet3_options', $updatedPlanBeforeToAddDatabase->packet3_options) + ->call('publish') + ->assertSuccessful() + ->assertHasNoErrors(['name', 'image', 'duration', 'details', 'packets_count', 'packet1_options', 'packet2_options', 'packet3_options']); + + $updatedPlanAfterToAddDatabase = Plan::orderByDesc('id')->first(); + + $newPlanUrl = route('plan.show', $updatedPlanAfterToAddDatabase); + + Storage::disk('tmp-for-tests')->assertExists($updatedPlanAfterToAddDatabase->image); + + + // check data after update recipe + self::assertEquals($updatedPlanBeforeToAddDatabase->name, $updatedPlanAfterToAddDatabase->name); + self::assertEquals($updatedPlanBeforeToAddDatabase->duration, $updatedPlanAfterToAddDatabase->duration); + self::assertEquals($updatedPlanBeforeToAddDatabase->state, $updatedPlanAfterToAddDatabase->state); + self::assertEquals($updatedPlanBeforeToAddDatabase->type, $updatedPlanAfterToAddDatabase->type); + self::assertEquals($updatedPlanBeforeToAddDatabase->details, $updatedPlanAfterToAddDatabase->details); + self::assertEquals($updatedPlanBeforeToAddDatabase->packets_count, $updatedPlanAfterToAddDatabase->packets_count); + self::assertEquals($updatedPlanBeforeToAddDatabase->packet1_options, $updatedPlanAfterToAddDatabase->packet1_options); + self::assertEquals($updatedPlanBeforeToAddDatabase->packet2_options, $updatedPlanAfterToAddDatabase->packet2_options); + self::assertEquals($updatedPlanBeforeToAddDatabase->packet3_options, $updatedPlanAfterToAddDatabase->packet3_options); + + $testCase->assertRedirect($newPlanUrl); + + } + + public function test_to_draft_new_plan_success(): void + { + $this->actingAs($this->user); + + $updatedPlanBeforeToAddDatabase = Plan::factory()->make(); + + $testCase = Livewire::test(Edit::class, [ + 'plan' => $this->plan, + ]) + ->set('name', $updatedPlanBeforeToAddDatabase->name) + ->assertSet('name', $updatedPlanBeforeToAddDatabase->name) + ->set('image', $this->image) + ->set('duration', $updatedPlanBeforeToAddDatabase->duration) + ->assertSet('duration', $updatedPlanBeforeToAddDatabase->duration) + ->set('state', $updatedPlanBeforeToAddDatabase->state) + ->assertSet('state', $updatedPlanBeforeToAddDatabase->state) + ->set('type', $updatedPlanBeforeToAddDatabase->type) + ->assertSet('type', $updatedPlanBeforeToAddDatabase->type) + ->set('details', $updatedPlanBeforeToAddDatabase->details) + ->assertSet('details', $updatedPlanBeforeToAddDatabase->details) + ->set('packets_count', $updatedPlanBeforeToAddDatabase->packets_count) + ->assertSet('packets_count', $updatedPlanBeforeToAddDatabase->packets_count) + ->set('packet1_options', $updatedPlanBeforeToAddDatabase->packet1_options) + ->assertSet('packet1_options', $updatedPlanBeforeToAddDatabase->packet1_options) + ->set('packet2_options', $updatedPlanBeforeToAddDatabase->packet2_options) + ->assertSet('packet2_options', $updatedPlanBeforeToAddDatabase->packet2_options) + ->set('packet3_options', $updatedPlanBeforeToAddDatabase->packet3_options) + ->assertSet('packet3_options', $updatedPlanBeforeToAddDatabase->packet3_options) + ->call('addToDrafts') + ->assertSuccessful() + ->assertHasNoErrors(['name', 'image', 'duration', 'details', 'packets_count', 'packet1_options', 'packet2_options', 'packet3_options']); + + $updatedPlanAfterToAddDatabase = Plan::orderByDesc('id')->first(); + + $newPlanUrl = route('plan.show', $updatedPlanAfterToAddDatabase, false); + + Storage::disk('tmp-for-tests')->assertExists($updatedPlanAfterToAddDatabase->image); + + // check data after update recipe + self::assertEquals($updatedPlanBeforeToAddDatabase->name, $updatedPlanAfterToAddDatabase->name); + self::assertEquals($updatedPlanBeforeToAddDatabase->duration, $updatedPlanAfterToAddDatabase->duration); + self::assertEquals('draft', $updatedPlanAfterToAddDatabase->state); + self::assertEquals($updatedPlanBeforeToAddDatabase->type, $updatedPlanAfterToAddDatabase->type); + self::assertEquals($updatedPlanBeforeToAddDatabase->details, $updatedPlanAfterToAddDatabase->details); + self::assertEquals($updatedPlanBeforeToAddDatabase->packets_count, $updatedPlanAfterToAddDatabase->packets_count); + self::assertEquals($updatedPlanBeforeToAddDatabase->packet1_options, $updatedPlanAfterToAddDatabase->packet1_options); + self::assertEquals($updatedPlanBeforeToAddDatabase->packet2_options, $updatedPlanAfterToAddDatabase->packet2_options); + self::assertEquals($updatedPlanBeforeToAddDatabase->packet3_options, $updatedPlanAfterToAddDatabase->packet3_options); + + $testCase->assertRedirect($newPlanUrl); + } + + public function test_to_preview_new_plan_success(): void + { + $this->actingAs($this->user); + + $updatedPlanBeforeToAddDatabase = Plan::factory()->make(); + + $testCase = Livewire::test(Edit::class, [ + 'plan' => $this->plan, + ]) + ->set('name', $updatedPlanBeforeToAddDatabase->name) + ->assertSet('name', $updatedPlanBeforeToAddDatabase->name) + ->set('image', $this->image) + ->set('duration', $updatedPlanBeforeToAddDatabase->duration) + ->assertSet('duration', $updatedPlanBeforeToAddDatabase->duration) + ->set('state', $updatedPlanBeforeToAddDatabase->state) + ->assertSet('state', $updatedPlanBeforeToAddDatabase->state) + ->set('type', $updatedPlanBeforeToAddDatabase->type) + ->assertSet('type', $updatedPlanBeforeToAddDatabase->type) + ->set('details', $updatedPlanBeforeToAddDatabase->details) + ->assertSet('details', $updatedPlanBeforeToAddDatabase->details) + ->set('packets_count', $updatedPlanBeforeToAddDatabase->packets_count) + ->assertSet('packets_count', $updatedPlanBeforeToAddDatabase->packets_count) + ->set('packet1_options', $updatedPlanBeforeToAddDatabase->packet1_options) + ->assertSet('packet1_options', $updatedPlanBeforeToAddDatabase->packet1_options) + ->set('packet2_options', $updatedPlanBeforeToAddDatabase->packet2_options) + ->assertSet('packet2_options', $updatedPlanBeforeToAddDatabase->packet2_options) + ->set('packet3_options', $updatedPlanBeforeToAddDatabase->packet3_options) + ->assertSet('packet3_options', $updatedPlanBeforeToAddDatabase->packet3_options) + ->call('showPreview') + ->assertSuccessful() + ->assertHasNoErrors(['name', 'image', 'duration', 'details', 'packets_count', 'packet1_options', 'packet2_options', 'packet3_options']); + + $updatedPlanAfterToAddDatabase = Plan::orderByDesc('id')->first(); + + $newPlanUrl = route('plan.show', $updatedPlanAfterToAddDatabase, false); + + Storage::disk('tmp-for-tests')->assertExists($updatedPlanAfterToAddDatabase->image); + + // check data after update recipe + self::assertEquals($updatedPlanBeforeToAddDatabase->name, $updatedPlanAfterToAddDatabase->name); + self::assertEquals($updatedPlanBeforeToAddDatabase->duration, $updatedPlanAfterToAddDatabase->duration); + self::assertEquals('unactive', $updatedPlanAfterToAddDatabase->state); + self::assertEquals($updatedPlanBeforeToAddDatabase->type, $updatedPlanAfterToAddDatabase->type); + self::assertEquals($updatedPlanBeforeToAddDatabase->details, $updatedPlanAfterToAddDatabase->details); + self::assertEquals($updatedPlanBeforeToAddDatabase->packets_count, $updatedPlanAfterToAddDatabase->packets_count); + self::assertEquals($updatedPlanBeforeToAddDatabase->packet1_options, $updatedPlanAfterToAddDatabase->packet1_options); + self::assertEquals($updatedPlanBeforeToAddDatabase->packet2_options, $updatedPlanAfterToAddDatabase->packet2_options); + self::assertEquals($updatedPlanBeforeToAddDatabase->packet3_options, $updatedPlanAfterToAddDatabase->packet3_options); + + $testCase->assertRedirect($newPlanUrl); + } + + public function testNothingChange(): void + { + $this->actingAs($this->user); + + $planUpdate = Livewire::test(Edit::class, [ + 'plan' => $this->plan, + ]) + ->call('publish') + ->assertSuccessful() + ->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']); + + $newPlanUrl = route('plan.show', $this->plan); + + Storage::disk('tmp-for-tests')->assertMissing($planUpdate->image); + + // check data after update recipe + self::assertEquals($this->plan->name, $planUpdate->name); + self::assertEquals($this->plan->duration, $planUpdate->duration); + self::assertEquals($this->plan->state, $planUpdate->state); + self::assertEquals($this->plan->type, $planUpdate->type); + self::assertEquals($this->plan->details, $planUpdate->details); + self::assertEquals($this->plan->packets_count, $planUpdate->packets_count); + self::assertIsArray($planUpdate->packet1_options); + self::assertIsArray($planUpdate->packet2_options); + self::assertIsArray($planUpdate->packet3_options); + + $planUpdate->assertRedirect($newPlanUrl); + } + +} + diff --git a/tests/Feature/Plan/IndexTest.php b/tests/Feature/Plan/IndexTest.php new file mode 100644 index 0000000..18c01da --- /dev/null +++ b/tests/Feature/Plan/IndexTest.php @@ -0,0 +1,35 @@ +refreshApplicationWithLocale('en'); + + $this->user = User::factory()->create(['is_consultant' => true]); + $this->plan = Plan::inRandomOrder()->first(); + } + + public function test_index_page_success(): void + { + $response = $this + ->actingAs($this->user) + ->get(route('plan.index')); + + $response + ->assertOk(); + } +} diff --git a/tests/Feature/Plan/ShowTest.php b/tests/Feature/Plan/ShowTest.php index 7c060d3..2578ad4 100644 --- a/tests/Feature/Plan/ShowTest.php +++ b/tests/Feature/Plan/ShowTest.php @@ -2,15 +2,11 @@ namespace Tests\Feature\Plan; -use App\Livewire\Plan\Create; use App\Models\Plan; -// use Livewire\WithFileUploads; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; -// use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; -use Livewire\Livewire; use Tests\TestCase; class ShowTest extends TestCase @@ -18,9 +14,7 @@ class ShowTest extends TestCase // use RefreshDatabase; use RefreshDatabase; - private $image; - - private $plan; + private Plan $plan; protected User $user; @@ -28,14 +22,11 @@ class ShowTest extends TestCase { $this->refreshApplicationWithLocale('en'); - Storage::fake('plans'); - $this->image = UploadedFile::fake()->image('plan.png'); - $this->user = User::factory()->create(['is_consultant' => true]); $this->plan = Plan::inRandomOrder()->first(); } - public function test_show_page_success() + public function test_show_page_success(): void { $response = $this->actingAs($this->user) ->get(route('plan.show', $this->plan, false)); diff --git a/tests/Feature/Product_Nutritional/CreateTest.php b/tests/Feature/Product_Nutritional/CreateTest.php new file mode 100644 index 0000000..04407e5 --- /dev/null +++ b/tests/Feature/Product_Nutritional/CreateTest.php @@ -0,0 +1,209 @@ +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()); +// } +// } diff --git a/tests/Feature/Product_Nutritional/EditTest.php b/tests/Feature/Product_Nutritional/EditTest.php new file mode 100644 index 0000000..c1845fb --- /dev/null +++ b/tests/Feature/Product_Nutritional/EditTest.php @@ -0,0 +1,105 @@ +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); + } +} diff --git a/tests/Feature/Product_Nutritional/IndexTest.php b/tests/Feature/Product_Nutritional/IndexTest.php new file mode 100644 index 0000000..3f4732e --- /dev/null +++ b/tests/Feature/Product_Nutritional/IndexTest.php @@ -0,0 +1,35 @@ +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(); + } +} diff --git a/tests/Feature/Product_Nutritional/ShowTest.php b/tests/Feature/Product_Nutritional/ShowTest.php new file mode 100644 index 0000000..4c978e7 --- /dev/null +++ b/tests/Feature/Product_Nutritional/ShowTest.php @@ -0,0 +1,47 @@ +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); + + // } +} diff --git a/tests/Feature/ProfileInformationTest.php b/tests/Feature/ProfileInformationTest.php index ce1a8e7..efec53d 100644 --- a/tests/Feature/ProfileInformationTest.php +++ b/tests/Feature/ProfileInformationTest.php @@ -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 diff --git a/tests/Feature/Recipe/CreateTest.php b/tests/Feature/Recipe/CreateTest.php index 3bb77ce..9f4d0e7 100644 --- a/tests/Feature/Recipe/CreateTest.php +++ b/tests/Feature/Recipe/CreateTest.php @@ -1,6 +1,4 @@ -refreshApplicationWithLocale('en'); - Storage::fake('recipes'); + Storage::fake('tmp-for-tests'); $this->image = UploadedFile::fake()->image('recipe.jpg'); @@ -55,7 +52,7 @@ final class CreateTest extends TestCase self::assertEquals($this->recipe->count(), $count = Recipe::count()); - Livewire::test(Create::class) + $testCase = Livewire::test(Create::class) ->set('title', $this->recipe->title) ->assertSet('title', $this->recipe->title) ->set('image', $this->image) @@ -75,7 +72,13 @@ final class CreateTest extends TestCase ->assertSuccessful() ->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']); - Storage::disk('public')->assertExists($this->recipe->image); + $lastCreatedRecipe = Recipe::orderByDesc('id')->first(); + + $newRecipeUrl = route('recipe.show', $lastCreatedRecipe, false); + + Storage::disk('tmp-for-tests')->assertExists($lastCreatedRecipe->image); + + $testCase->assertRedirect($newRecipeUrl); self::assertEquals($count + 1, Recipe::count()); } @@ -86,7 +89,7 @@ final class CreateTest extends TestCase self::assertEquals($this->recipe->count(), $count = Recipe::count()); - Livewire::test(Create::class) + $testCase = Livewire::test(Create::class) ->set('title', $this->recipe->title) ->assertSet('title', $this->recipe->title) ->set('image', $this->image) @@ -106,7 +109,13 @@ final class CreateTest extends TestCase ->assertSuccessful() ->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']); - Storage::disk('public')->assertExists($this->recipe->image); + $lastCreatedRecipe = Recipe::orderByDesc('id')->first(); + + $newRecipeUrl = route('recipe.show', $lastCreatedRecipe, false); + + // Storage::disk('tmp-for-tests')->assertExists($lastCreatedRecipe->image); + + $testCase->assertRedirect($newRecipeUrl); self::assertEquals($count + 1, Recipe::count()); @@ -119,7 +128,7 @@ final class CreateTest extends TestCase self::assertEquals($this->recipe->count(), $count = Recipe::count()); - Livewire::test(Create::class) + $testCase = Livewire::test(Create::class) ->set('title', $this->recipe->title) ->assertSet('title', $this->recipe->title) ->set('image', $this->image) @@ -139,7 +148,13 @@ final class CreateTest extends TestCase ->assertSuccessful() ->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']); - Storage::disk('public')->assertExists($this->recipe->image); + $lastCreatedRecipe = Recipe::orderByDesc('id')->first(); + + $newRecipeUrl = route('recipe.show', $lastCreatedRecipe, false); + + // Storage::disk('tmp-for-tests')->assertExists($lastCreatedRecipe->image); + + $testCase->assertRedirect($newRecipeUrl); self::assertEquals($count + 1, Recipe::count()); @@ -161,7 +176,7 @@ final class CreateTest extends TestCase ->set('type', null) ->set('description', null) ->call('publish') - ->assertHasErrors(['image', 'state', 'type', 'description']); + ->assertHasErrors(['image', 'description']); // doesnt to add to database self::assertEquals($count, Recipe::count()); @@ -196,4 +211,3 @@ final class CreateTest extends TestCase self::assertEquals($count, Recipe::count()); } } - diff --git a/tests/Feature/Recipe/EditTest.php b/tests/Feature/Recipe/EditTest.php index ba5bb22..d68d2f2 100644 --- a/tests/Feature/Recipe/EditTest.php +++ b/tests/Feature/Recipe/EditTest.php @@ -8,6 +8,7 @@ use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Storage; use Livewire\Livewire; +use Illuminate\Http\UploadedFile; use Tests\TestCase; /** @@ -21,12 +22,18 @@ final class EditTest extends TestCase private Recipe $recipe; + private UploadedFile $image; + public function setUp(): void { $this->refreshApplicationWithLocale('en'); $this->user = User::factory()->create(['is_consultant' => true]); + Storage::fake('tmp-for-tests'); + + $this->image = UploadedFile::fake()->image('recipe.jpg'); + $this->recipe = Recipe::inRandomOrder()->first(); } @@ -50,7 +57,7 @@ final class EditTest extends TestCase ]) ->set('title', $recipe->title) ->assertSet('title', $recipe->title) - ->set('image', $recipe->image) + ->set('image', $this->image) ->set('state', $recipe->state) ->assertSet('state', $recipe->state) ->set('cooking_time', $recipe->cooking_time) @@ -67,17 +74,23 @@ final class EditTest extends TestCase ->assertSuccessful() ->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']); - Storage::disk('public')->assertExists($this->recipe->image); + + $recipeCreatedLast = Recipe::orderByDesc('id')->first(); + $newRecipeUrl = route('recipe.show', $recipeCreatedLast, false); + + Storage::disk('tmp-for-tests')->assertExists($recipeCreatedLast->image); // check data after update recipe self::assertEquals($recipe->title, $recipeUpdate->title); - self::assertEquals($recipe->image, $recipeUpdate->image); self::assertEquals($recipe->state, $recipeUpdate->state); self::assertEquals($recipe->cooking_time, $recipeUpdate->cooking_time); self::assertEquals($recipe->ingredients, $recipeUpdate->ingredients); self::assertEquals($recipe->type, $recipeUpdate->type); self::assertEquals($recipe->description, $recipeUpdate->description); self::assertEquals($recipe->video_url, $recipeUpdate->video_url); + + $recipeUpdate->assertRedirect($newRecipeUrl); + } @@ -109,17 +122,21 @@ final class EditTest extends TestCase ->assertSuccessful() ->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']); - Storage::disk('public')->assertExists($this->recipe->image); + $recipeCreatedLast = Recipe::orderByDesc('id')->first(); + $newRecipeUrl = route('recipe.show', $recipeCreatedLast, false); + + Storage::disk('tmp-for-tests')->assertExists($recipeCreatedLast->image); // check data after update recipe self::assertEquals($recipe->title, $recipeUpdate->title); - self::assertEquals($recipe->image, $recipeUpdate->image); self::assertEquals('archived', $recipeUpdate->state); self::assertEquals($recipe->cooking_time, $recipeUpdate->cooking_time); self::assertEquals($recipe->ingredients, $recipeUpdate->ingredients); self::assertEquals($recipe->type, $recipeUpdate->type); self::assertEquals($recipe->description, $recipeUpdate->description); self::assertEquals($recipe->video_url, $recipeUpdate->video_url); + + $recipeUpdate->assertRedirect($newRecipeUrl); } @@ -151,17 +168,22 @@ final class EditTest extends TestCase ->assertSuccessful() ->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']); - Storage::disk('public')->assertExists($this->recipe->image); + $recipeCreatedLast = Recipe::orderByDesc('id')->first(); + $newRecipeUrl = route('recipe.show', $recipeCreatedLast, false); + + Storage::disk('tmp-for-tests')->assertExists($recipeCreatedLast->image); // check data after update recipe self::assertEquals($recipe->title, $recipeUpdate->title); - self::assertEquals($recipe->image, $recipeUpdate->image); self::assertEquals('archived', $recipeUpdate->state); self::assertEquals($recipe->cooking_time, $recipeUpdate->cooking_time); self::assertEquals($recipe->ingredients, $recipeUpdate->ingredients); self::assertEquals($recipe->type, $recipeUpdate->type); self::assertEquals($recipe->description, $recipeUpdate->description); self::assertEquals($recipe->video_url, $recipeUpdate->video_url); + + + $recipeUpdate->assertRedirect($newRecipeUrl); } @@ -176,17 +198,21 @@ final class EditTest extends TestCase ->assertSuccessful() ->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']); - Storage::disk('public')->assertExists($this->recipe->image); + $recipeCreatedLast = Recipe::orderByDesc('id')->first(); + $newRecipeUrl = route('recipe.show', $this->recipe, false); + + Storage::disk('tmp-for-tests')->assertMissing($recipeCreatedLast->image); // check data after update recipe self::assertEquals($this->recipe->title, $recipeUpdate->title); - self::assertEquals($this->recipe->image, $recipeUpdate->image); self::assertEquals($this->recipe->state, $recipeUpdate->state); self::assertEquals($this->recipe->cooking_time, $recipeUpdate->cooking_time); self::assertEquals($this->recipe->ingredients, $recipeUpdate->ingredients); self::assertEquals($this->recipe->type, $recipeUpdate->type); self::assertEquals($this->recipe->description, $recipeUpdate->description); self::assertEquals($this->recipe->video_url, $recipeUpdate->video_url); + + $recipeUpdate->assertRedirect($newRecipeUrl); } } diff --git a/tests/Feature/Recipe/IndexTest.php b/tests/Feature/Recipe/IndexTest.php index 13557f0..4c264e8 100644 --- a/tests/Feature/Recipe/IndexTest.php +++ b/tests/Feature/Recipe/IndexTest.php @@ -11,7 +11,7 @@ class IndexTest extends TestCase { use RefreshDatabase; - private Recipe $recipe; + public Recipe $recipe; protected User $user; @@ -23,7 +23,7 @@ class IndexTest extends TestCase $this->recipe = Recipe::inRandomOrder()->first(); } - public function test_index_page_success() + public function test_index_page_success(): void { $response = $this ->actingAs($this->user) diff --git a/tests/Feature/Recipe/ShowTest.php b/tests/Feature/Recipe/ShowTest.php index cc71420..1b93854 100644 --- a/tests/Feature/Recipe/ShowTest.php +++ b/tests/Feature/Recipe/ShowTest.php @@ -23,7 +23,7 @@ class ShowTest extends TestCase $this->recipe = Recipe::inRandomOrder()->first(); } - public function test_show_page_success() + public function test_show_page_success(): void { $response = $this->actingAs($this->user) ->get(route('recipe.show', $this->recipe, false)); diff --git a/tests/Feature/RegistrationTest.php b/tests/Feature/RegistrationTest.php index a87e034..db8a9d2 100644 --- a/tests/Feature/RegistrationTest.php +++ b/tests/Feature/RegistrationTest.php @@ -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', [ diff --git a/tests/Feature/TwoFactorAuthenticationSettingsTest.php b/tests/Feature/TwoFactorAuthenticationSettingsTest.php index 686bb02..1321659 100644 --- a/tests/Feature/TwoFactorAuthenticationSettingsTest.php +++ b/tests/Feature/TwoFactorAuthenticationSettingsTest.php @@ -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()); diff --git a/tests/TestCase.php b/tests/TestCase.php index ed6b3ad..cb21dbc 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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);