PetrKaterinak

PetrKaterinak

Member Since 5 Months Ago

Experience Points
10,610
Total
Experience

4,390 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
97
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 3
10,610 XP
Aug
21
4 weeks ago
Activity icon

Replied to Checkboxes Validation

Thanks a lot, I've never used names as arrays before... As first checkbox was mentioned that one marked as |x|, but I got your explanation. Need to take a lesson about array names now 😁

Activity icon

Started a new Conversation Checkboxes Validation

Hi, do you have any idea, how to use laravel validation, to validate checkboxes example below?

|x| I have learning disabilities  // when this is clicked, checkboxes below appears
       |1| Dyslexia
       |2| Dysgraphia
       |3| Dysortographia
       |4| Discalculia
	I received this diagnosis from:
       |5| EPC (psychologist)
       |6| Psychiatrics / Neurologist

There are exactly two conditions in total:

  • If 1st checkox is not checked, everything is ok and nothing is saved to db
  • If 1st checkbox is checked, at least one of [1,2,3,4] checkboxes must be checked and at least one of [5,6] checkboxes must be checked. Then I save it to db to column "learning_disabilities" as a string e.g. "1,2,6"
Aug
19
1 month ago
Activity icon

Replied to How To Load Model With Conditional WhereHas Relationship?

Oh yes, I tried it before, but this returns me first client at db. Not first client with order piced above 100 000.

And his orders in received collection are just empty collection. If I manually look on it, it is true, this client doesn't have orders with price >= 100 000. He has orders with price 17 800 and 22 350.

Activity icon

Started a new Conversation How To Load Model With Conditional WhereHas Relationship?

Hi there, easiest description of my question is to show what I've tried and what I need to get:

Client::with('orders')->first();

Returns me first client together with all its orders

Client::whereHas('orders', function($q){ $q->where('price', '>=', 100000); })->first();

This gives me client, which have at least one order with price >= 100 000, but I'm missing that eager loaded orders here

Client::with('orders')->whereHas('orders', function($q){ $q->where('price', '>=', 100000); })->first();

This is almost, what I need, it gives me client, which have at least one order with price >= 100 000 and eager loads all its orders

What I need is the third variant, but with eager loaded only orders with price >= 100 000. Is there any way to load what I need?

Aug
05
1 month ago
Activity icon

Replied to Laravel 7 - LoginController - Allow Only Users With "active=1"

Finaly, I found it myself by checking AuthenticatesUsers trait: In LoginController is required to add:

public function attemptLogin(Request $request)
    {
        return $this->guard()->attempt(
            ['email' => $request->email, 'password' => $request->password, 'active' => 1],
            $request->filled('remember')
        );
    }

So what's wrong with the Laravel's manual?

Activity icon

Started a new Conversation Laravel 7 - LoginController - Allow Only Users With "active=1"

Hi there, I searched over the internet and almost all answers went to https://laravel.com/docs/7.x/authentication#authenticating-users . So I used it. In database I have a few testing users with extra column "active". Only one of them have active = 1.

By the Laravel manual I've added this to the LoginController:

public function authenticate(Request $request)
    {
        if (Auth::attempt(['email' => $request->email, 'password' => $request->password, 'active' => 1], $request->remember)) {
            return redirect('/admin');
        }
    }

But I'm still able to login as user, which have active = 0. What is wrong with my code?

Jul
23
1 month ago
Activity icon

Awarded Best Reply on Select Models, Where Key = Modified String

Thanks, but it didn't worked. Yes, I was able to get value by $userBankAcc->accountWithoutDashes, but UserBankAccount::where(['accountWithoutDashes' => '123456789'])->first() throws error, that accountWithoutDashes column not exists. Finaly colleague gave me a solution with raw:

$acc_number = "123456789";
UserBankAccount::whereRaw('REPLACE(`acc_number`, "-", "") = "' . $acc_number . '"')->first();

Jul
22
1 month ago
Activity icon

Replied to Select Models, Where Key = Modified String

Thanks, but it didn't worked. Yes, I was able to get value by $userBankAcc->accountWithoutDashes, but UserBankAccount::where(['accountWithoutDashes' => '123456789'])->first() throws error, that accountWithoutDashes column not exists. Finaly colleague gave me a solution with raw:

$acc_number = "123456789";
UserBankAccount::whereRaw('REPLACE(`acc_number`, "-", "") = "' . $acc_number . '"')->first();

Activity icon

Started a new Conversation Select Models, Where Key = Modified String

Hi there, it is about bank accounts. Let's say, that user have bank account "123-1456789". This value is stored in db and is used in this exact format on many places of application, containing bank payments. But the important thing is, that when payment come from bank, it is formated as "123456789" (without dash).

Question: How to find if 123456789 exists in db? Expected result is, that it exists.


$bankAccountExists = UserBankAccount::where('acc_number', '123456789)->count();
// Maybe some RAW is needed to convert value first to value without dash? How?
Jun
25
2 months ago
Activity icon

Replied to Show And Select SQL-Enum In Form-select

Just create function e.g. in helper file:

function getEnumValues(string $table, string $column): array
    {
        $enumStr = DB::select(DB::raw("SHOW COLUMNS FROM $table WHERE Field = '$column'"))[0]->Type;
        preg_match_all("/'([^']+)'/", $enumStr, $matches);
        return isset($matches[1]) ? $matches[1] : [];
    }

and then inject its result by controller into view, then by @foreach loop fill the dropdown items

May
17
4 months ago
Activity icon

Commented on Build A Like/Dislike System

I also spent a lot of time to search why it is not working and where I missed update of User class in video, but it is not in there...

May
07
4 months ago
Activity icon

Started a new Conversation Scope To Filter Users Which Have At Least One Active Order

Hi there, can you help me, please, how to define scope to

  • return collection of USER model, (which have one to many relationship to ORDER model)
  • where count of orders with ORDER model attributes finished_at and deleted_at equals to null is greater than zero?
/// On User model
public function scopeHasActiveOrder($query): Builder
    {
        return $query->with('order')->whereHas('order', function($query){
	    $activeOrdersCount = Orders::where([
		"id", $this->id,
		['finished_at', '!=', null],
                ['deleted_at', '!=', null],
	     ])->count();
            /// How to allow/disallow to add to the scope's collection here?
        });
    }