Skip to content
On this page

Use IoC container for long term projects

new Class syntax creates tight coupling between classes and complicates testing. Use IoC container or facades instead.

Bad:

php
$user = new User;
$user->create($request->validated());

Good:

php
public function __construct(User $user)
{
    $this->user = $user;
}

....

$this->user->create($request->validated());