Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Builder: in View, Validation, Relationships

Premium
3 min read

So, we move into the world of patterns inside the framework itself, starting with Builder.

Of course, the Builder pattern can be seen in more places than just your code - for example, in the /vendor folder!


Builder in View

Take a look at this code.

Some Controller

return view('greeting')
->with('name', 'Victoria')
->with('occupation', 'Astronaut');

It's a typical Laravel view usage, but if we look closer, it's a Builder pattern!

Especially if we take a look at the source code of the ->with() method, we can see that it returns $this:

Illuminate/View/View.php

public function with($key, $value = null)
{
if (is_array($key)) {
$this->data = array_merge($this->data, $key);
} else {
$this->data[$key] = $value;
}
 
return $this;
}

In this case, the Builder pattern is one of...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.