Member Since 2 Years Ago

Kampen, The Netherlands

Experience Points

2,610 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
Best Reply Awards
Best Reply
  • 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.


    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.


    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 4
17,390 XP
1 month ago
Activity icon

Replied to HasOneThrough On One Table

Indeed, it is bot possible but maybe I did something wrong but doesn’t look at it from getting your feedback, so I also opened an issue on the ideas repo of Laravel maybe they can give me a hint on what the best option is.

Activity icon

Replied to HasOneThrough On One Table

That’s where I started, this post if I use the hasOneThrough from the bottom up, so from the comment to the highest page. It would make a query with a join on his self but not adding an alias for the join clause.

2 months ago
Activity icon

Replied to HasOneThrough On One Table

@nakov Thanks for your reply, maybe the code below will give a better view of what I'm trying to solve.

So imagine that you have a page with subpages and they are both stored in the same table called pages and you also have a comment that is stored table called comments.

Important to know is that a subpage can not have subpages.

So the tables will look something like this:

pages table:

comments table:

And the models will have this relationships setup:

// Page model
public function parent()
    return $this->hasOne(Page::class, 'parent_id');

// Comment model
public function page()
    return $this->hasOne(Page::class);

Now you have two pages Questions about SMTP and How to setup SMTP on Apple and we have a comment that has over 100 upvotes that is connected to the How to setup SMTP on Apple page.

Let's say that on the page where you want to show all comments that has a voting of 100 or more and want to show the parent of the subpage that the comment is connected to.

So the code in most cases would look something like this:

$comments = Comment::where('votes_counter', '>=', 100)->with('page.parent')->get();
// or
$comments = Comment::where('votes_counter', '>=', 100)->with('page.parent')->whereHas('page.parent')->get();

foreach($comments as $comment) {
    echo $comment->page->parent->name;

So to show this you need three queries and in most systems that's fine, but if you have a lot of traffic it is not so handy.

Of course you also need to go through two relations to get the name you really wanted, but now you also loaded all the data of the subpage that the comment is connected to and you not even showing it somewhere.

// Query on the comments table
SELECT * FROM comments WHERE `votes_counter` >= 100

// Queries on the pages table
SELECT * FROM pages WHERE `id` IN(3, 4, 5)
// And the next to get the parent
SELECT * FROM pages WHERE `id` IN(1, 2) // 1 and 2 are the parent pages of 3, 4 and 5

So that's why I thought it would be great to use the hasOneThrough relation to load the parent page and save fetching all the data I don't even need.

2 months ago
Activity icon

Started a new Conversation HasOneThrough On One Table


I'm trying to set up a hasOneThrough relation on one table. But Eloquent will not look it the two tables are the same and add an alias for one of the tables.

The table looks something like this:

Product table:


So the end query will look like this:

select `products`.*, `products`.`parent_id` as `laravel_through_key` from `products` inner join `products` on `products`.`parent_id` = `products`.`id` where `products`.`id` in (?)

So my question is, is there an option to tell Eloquent that is should an as alias instead of the table name?

I know that I can eager loading them with chaining the relations but this would be better because I will not get any memory usage for the products that I don't even need.