Tuesday, October 30, 2018

Dependency injection vs just using facades?

Dependency injection vs just using facades?

Hi guys, I see a lot of people recommending this:
use App\User;

class BlahController extends Controller {

    protected $user;

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

    public function show($id)
    {
        return $this->user->find($id);
    }

}
Over this:
use App\User;

class BlahController extends Controller {

    public function show($id)
    {
        return User::find($id);
    }

}

REST API CRUD With Laravel 5 and Fractal

Laravel Rest Api CRUD