make static-analyse code

This commit is contained in:
2024-01-15 01:05:10 +03:00
parent 57244b63be
commit bc2c8df9af
35 changed files with 221 additions and 182 deletions

View File

@@ -7,13 +7,14 @@ use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
use Illuminate\Http\UploadedFile;
class UpdateUserProfileInformation implements UpdatesUserProfileInformation
{
/**
* Validate and update the given user's profile information.
*
* @param array<string, string> $input
* @param array<string|UploadedFile> $input
*/
public function update(User $user, array $input): void
{

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,23 +3,26 @@
namespace App\Livewire\Chat;
use Livewire\Component;
use Illuminate\View\View;
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'];
protected function getListeners(): array
{
return ['echo:direct-chat,ChatMessageUpdated' => 'notifyNewMessage'];
}
public function notifyNewMessage($payload): void
public function notifyNewMessage(string $payload): void
{
$this->myMessages[] = $payload;
$this->showNewMessageNotifycation = true;
}
public function render()
public function render(): View
{
return view('livewire.chat.tracker');
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -18,9 +18,9 @@ class EditDetailzForm extends Component
public string $currentPassword;
public string $newPassword;
public string $newPassword = '';
public string $newPasswordConfirm;
public string $newPasswordConfirm = '';
public array $validatedData = [];

View File

@@ -7,20 +7,23 @@ use App\Models\Tag;
use Illuminate\View\View;
use Livewire\Attributes\On;
use Livewire\Component;
use Illuminate\Database\Eloquent\Model;
use App\Models\Recipe;
use App\Models\BlogPost;
class TagsComponent extends Component
{
public string $tags;
public $parentComponent;
public Recipe|BlogPost $parentComponent;
// protected $listeners = ['tagAdded', 'tagRemoved'];
public function mount($parentComponent = null): void
public function mount(Recipe|BlogPost $parentComponent = null): void
{
// $curTags = $parentComponent ? $parentComponent->tags->unique()->pluck('name') : [];
$curTags = $parentComponent ? $parentComponent->tags->unique()->pluck('name') : [];
/* $allTags = Tag::all(); */
$curTags = $parentComponent && isset($parentComponent['tags']) ? $parentComponent['tags']->unique()->pluck('name') : [];
// $curTags = $parentComponent && isset($parentComponent['tags']) ? $parentComponent['tags']->unique()->pluck('name') : [];
$this->tags = json_encode($curTags);
}

View File

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

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
/**
* App\Models\Chat
@@ -36,7 +37,7 @@ class Chat extends Model
protected $casts = ['created_at' => 'datetime:Y-m-d H:i:s'];
public function scopeWithLastUserMessage(mixed $query, int $userId)
public function scopeWithLastUserMessage(Builder $query, int $userId): Model|null
{
return $query
->where('from_user_id', $userId)
@@ -45,7 +46,7 @@ class Chat extends Model
->first();
}
public function scopeWithLastTenMessages(mixed $query, int $userId, int $recipientId)
public function scopeWithLastTenMessages(Builder $query, int $userId, int $recipientId): Builder
{
return $query
->where('from_user_id', $userId)
@@ -58,7 +59,7 @@ class Chat extends Model
->limit(20);
}
public function scopeWithLastMessage(mixed $query, int $userId, int $recipientId)
public function scopeWithLastMessage(Builder $query, int $userId, int $recipientId): Model|null
{
return $query
->where('from_user_id', $userId)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -4,6 +4,9 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
/**
* App\Models\UserAttachment
@@ -44,17 +47,17 @@ class UserAttachment extends Model
protected $guarded = [];
public function user()
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function scopeCerts($query)
public function scopeCerts(Builder $query): Builder
{
return $query->where('user_attachments.group', 'user_certs');
}
public function meals()
public function meals(): BelongsToMany
{
return $this->belongsToMany(Meal::class);
}

View File

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

View File

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

View File

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

View File

@@ -6,21 +6,21 @@ use Illuminate\Contracts\Validation\Rule;
class MinWords implements Rule
{
protected $minWords;
protected int $minWords;
public function __construct($minWords)
public function __construct(int $minWords)
{
$this->minWords = $minWords;
}
public function passes($attribute, $value)
public function passes(mixed $attribute, mixed $value): bool|int
{
$wordCount = count(preg_split('/\W+/u', $value, -1, PREG_SPLIT_NO_EMPTY));
return $wordCount >= $this->minWords;
}
public function message()
public function message(): string
{
return "The :attribute must have at least {$this->minWords} words.";
}

View File

@@ -7,52 +7,56 @@ use App\Models\Recipe;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Collection;
class FeedService
{
public static function showActualFeed()
public static function showActualFeed(): Collection
{
$dateMax = Recipe::max('created_at');
$dateMin = Carbon::parse($dateMax)->subDays(10);
$sql = <<<'EOF'
SELECT
p.id,
p.title,
(
(p.likes_count + p.comments_count) /
((UNIX_TIMESTAMP(GREATEST(p.created_at,
COALESCE((SELECT MAX(l.created_at) FROM blog_post_likes l WHERE l.blog_post_id = p.id), p.created_at),
COALESCE((SELECT MAX(c.created_at) FROM blog_post_comments c WHERE c.blog_post_id = p.id), p.created_at)
)) - UNIX_TIMESTAMP(p.created_at))/60 + 1
) ^ 1.8
) AS popularity
FROM
(SELECT
`blog_posts`.id,
blog_posts.title,
blog_posts.created_at,
COUNT(blog_post_comments.id) AS comments_count,
COUNT(blog_post_likes.id) AS likes_count
FROM
`blog_posts`
LEFT JOIN blog_post_comments ON blog_post_comments.blog_post_id = blog_posts.id
LEFT JOIN blog_post_likes ON blog_post_likes.blog_post_id = blog_posts.id
GROUP BY blog_posts.id) p
ORDER BY popularity DESC;
EOF;
SELECT
p.id,
p.title,
(
(p.likes_count + p.comments_count) /
((UNIX_TIMESTAMP(GREATEST(p.created_at,
COALESCE((SELECT MAX(l.created_at) FROM blog_post_likes l WHERE l.blog_post_id = p.id), p.created_at),
COALESCE((SELECT MAX(c.created_at) FROM blog_post_comments c WHERE c.blog_post_id = p.id), p.created_at)
)) - UNIX_TIMESTAMP(p.created_at))/60 + 1
) ^ 1.8
) AS popularity
FROM
(SELECT
`blog_posts`.id,
blog_posts.title,
blog_posts.created_at,
COUNT(blog_post_comments.id) AS comments_count,
COUNT(blog_post_likes.id) AS likes_count
FROM
`blog_posts`
LEFT JOIN blog_post_comments ON blog_post_comments.blog_post_id = blog_posts.id
LEFT JOIN blog_post_likes ON blog_post_likes.blog_post_id = blog_posts.id
GROUP BY blog_posts.id) p
ORDER BY popularity DESC;
EOF;
$hotBlogPosts = collect(
DB::select(DB::raw($sql))
)->map(fn ($post) => BlogPost::find($post->id))
->take(16)->chunk(4);
DB::select($sql)
)
->map(fn($post) => BlogPost::find($post->id))
->take(16)
->chunk(4);
$newbiesBlogPosts = User::orderBy('created_at', 'desc')
->withCount('author_of_blog_post')
->get()
->filter(fn ($u) => $u->author_of_blog_post_count > 0)->take(4)
->filter(fn($u) => $u->author_of_blog_post_count > 0)
->take(4)
->pluck('id')
->map(fn ($id) => User::find($id)->author_of_blog_post()->limit(2)->get())
->map(fn($id) => User::find($id)->author_of_blog_post()->limit(2)->get())
->flatten()
->random();
@@ -62,9 +66,14 @@ EOF;
->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);
return $firstCollection->concat($secondCollection)->filter(fn($el) => !is_null($el) && $el->id);
// $firstCollection = $hotBlogPosts->first()->push($newbiesBlogPosts->first())->push($randomRecipe->first());
// $secondCollection = $hotBlogPosts->skip(1)->first()->push($newbiesBlogPosts->skip(1)->first())->push($randomRecipe->skip(1)->first());
// return $firstCollection->concat($secondCollection)->filter(fn ($el) => ! is_null($el) && $el->id);
}
}

View File

@@ -11,7 +11,7 @@ return [
| using this Eloquent Model. You can override this if you really need to.
|
*/
'model' => \Tonysm\RichTextLaravel\Models\RichText::class,
// 'model' => \Tonysm\RichTextLaravel\Models\RichText::class,
/*
|--------------------------------------------------------------------------

View File

@@ -3,7 +3,7 @@
return [
'article' => [
// class of your domain object
'class' => App\Article::class,
// 'class' => App\Article::class,
// name of the graph (default is "default")
'graph' => 'article',

View File

@@ -4,6 +4,7 @@ namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use FakerRestaurant\Provider\en_US\Restaurant;
use Faker\Generator;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ProductGroup>

View File

@@ -2,11 +2,11 @@
namespace Database\Factories;
use App\Models\Team;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use Laravel\Jetstream\Features;
use Laravel\Jetstream\Team;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>

View File

@@ -6,12 +6,7 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('product_nutritional_values', function (Blueprint $table) {
$table->id();
@@ -33,12 +28,7 @@ return new class extends Migration
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('product_nutritional_values');
}