Zalo

Zalo

FullStack Developer at Madrid

Member Since 3 Years Ago

Madrid

Experience Points
60,830
Total
Experience

4,170 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
600
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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 13
60,830 XP
Dec
15
2 months ago
Activity icon

Replied to Eager Load Pivot Model Relations

Hi, i'm having the same problem. How did you solve it?

Oct
04
4 months ago
Activity icon

Replied to Query By Lastest Relationship Value

Omg guys, sorry. I finally get it work. The problem was in the subquery. One of the condition should be outside (I don't know why).

It is the resulted scope

/**
 * @return Builder
*/
public function scopeIsActive()
{
    return $this->builder->whereHas('statuses', function (Builder $q) {
        return $q->whereDate('date', '<=', today()) // This must be outside :D
            ->where('statuses.id', function ($sub) {
                return $sub->select('id')
                    ->from('statuses')
                    ->whereColumn('posts.id', 'post_id')
                    ->latest()
                    ->limit(1);
            });
    });
}
Activity icon

Replied to Query By Lastest Relationship Value

Nobody? I'm sure that someone have faced this issue before.

It is: How can you filter a Model by its latest Relationship value???

I want to use Eloquent and EagerLoading, so I need it in a query scope.

I tried using max(id) but looks like it doesnt work or I don't know how to use it.

Please, someone help me!

Thanks!

Oct
03
4 months ago
Activity icon

Started a new Conversation Query By Lastest Relationship Value

Hi all!

I need help!

I cant solve this issue, looks simple but I have failed in all my attempts... I'm trying to create a query scope that can filter Post models by latest relationship value.

Post model hasMany() Statuses, each status has a date.

Simple. So, a Post can has multiple Status childs, where the only one that Im interested is the last one, specifically its date.

So my Post model has:

public function status()
{
    return $this->hasOne(Status::class)->latest();
}

My first attempt was simple:

public function scopeIsActive($builder) 
{
    return $builder->whereHas('status', function($q) {
        // It doesnt work because its taking all related Statuses....
        return $q->whereDate('date', '<=', today());
    });
}

Despite hasOne(), it still is fetching all related Statuses instead of last one :( First strike.

My second attempt make me dig in the dark world of sub queries. I finally found something that looks cool, like this:

public function scopeIsActive($builder)
{
    return $builder->whereHas('status', function($q) { // So, I want Statuses!
        return $q->where('statuses.id', function($sub){ // BUT, i dont want all of them, lets find out wich one
            return $sub->select('id') // I'll find it by id
                    ->from('statuses') // So lets find what Status I want
                    ->where('post_id', 'statuses.id') // It must point to the Post
                    ->whereDate('date', '<=', today()) // It must satisfies a condition
                    ->latest() // And, I want the last created, so order with latest()
                    ->limit(1) // just pick one  <--- It seems to be not working!!!!!!!!
        });
    }
}

If it helps, it is the resulted SQL:

"select * from "posts" where exists (select * from "statuses" where "posts"."id" = "statuses"."post_id" and "statuses"."id" = (select "id" from "statuses" where "post_id" = "posts"."id" and strftime('%Y-%m-%d', "date") <= cast(? as text) order by "created_at" desc limit 1))

And thas all guys, how its possible!?

Nobody can help me T_T I can't believe I can't get it work... It still fetches all related Statuses instead of the last one...

Please help!

Thanks!

Oct
02
4 months ago
Activity icon

Replied to Latest Record From Relationship In WhereHas()

I'm having the same problem... I think you can't filter by ONLY the last related record...

Activity icon

Replied to WhereHas Latest Child Equals A Value

It doesnt work! When you use HasOne(...)->latest() you only are adding an orderBy() sql but it still will consider all related records, so, resulted sql will not be limited to ONLY the last record... If you use a '<=' comparison, this query will still give you all records instead of searching for ONLY the last one... Some one know how to face it with query builder? I think its not possible and you have to use DB::raw() thing.

Sep
11
5 months ago