1

I read that facades are not good. I have no idea if that is correct. I also read that Laravel uses a lot of them. Further, I read you can turn them off in Lumen. "Turn off" may not be the right word.

Do you have to use Laravel with facades? If I do not use the facades, does this mean I should probably not have chosen Laravel in the first place?

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
johnny
  • 19,272
  • 52
  • 157
  • 259

2 Answers2

3

You aren't forced to use facades.

Check documentation at https://laravel.com/docs/5.1/facades

Just use app helper to get what you need.

app('router');
app('config')

or you can use IoC. There are a lot of ways.

Danny
  • 444
  • 4
  • 19
  • Does it somehow defeat the purpose of choosing Laravel to begin with? – johnny May 24 '16 at 18:19
  • @johnny Nah, it isn't. It's like using ORM, you choose! :) – Danny May 24 '16 at 18:21
  • 3
    @johnny not at all, they are just syntactic sugar to ease on the learning curve. For many, an introduction to the concept of an IoC and dependency inversion in early stages of learning would put Laravel on a par with Symfony in terms of ease of understanding. Of course along with this 'sugar' comes a hefty amount of opinionated code, that rightly or wrongly also eases the learning curve for those new to Laravel, this is where the framework shines (and fails for some). – David Barker May 24 '16 at 18:24
  • @DavidBarker So it means lots of magic to some and they don't care, and to some it means they can skip "plumbing" and work on problems? – johnny May 24 '16 at 18:37
  • 1
    @johnny yep exactly that. Then there are those that love doing their own plumbing. – David Barker May 24 '16 at 19:11
2

In fact you don't need to use facades in your app. If you look at Facades class reference for each facade you can find class in this table. So for example instead of DB facade you can inject Illuminate\Database\DatabaseManager and you can use its method.

Using facade you would use:

DB:beginTransaction();

and injecting class and assigning it to class property you can write:

$this->db->beginTransaction();
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291