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!
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...