0

I do have ready the topics in the documentation, but please help me to know why this is the most correct way and what's wrong (and not enough) with methods like $this->load->model('User_model') or setting the /config/autoload.php configs in CodeIgniter?

In case we want to use additional controllers (like Request $request) as method injection, or UserRepository $users as contrustor injection (which is not a meaningful example in my opinion, but has be exampled in the main documentation) what's wrong with accessing those classes as properties (like $this->input->get('id')) or traits if we want to be committed to OOP concepts?

It more seems to be just coding style and framework conventions (which is of course important, too), isn't it?

Mohammad Naji
  • 5,372
  • 10
  • 54
  • 79
  • Can you provide some examples/some context to what `$this->load->model('User_model')` and `$this->input->get('id')` do and how you use them? – DevK May 27 '18 at 23:15
  • @devk I come from CodeIgniter. Using `$this->input->get('id')` we get `$_GET['id']`, but in Laravel we should access the `$request` instance on a per method basis with `Request $request` as a parameter. Also when we want to load a library/class, Laravel forces us to use Service Container and Service Provider. But in CodeIgniter it was as easy as just `$this->load->model('User_model')` or `$this->load->library('Paypal_gayment')` and we would then access it with `$this->user_model` or `$this->paypal_gateway`. – Mohammad Naji May 28 '18 at 00:16
  • 1
    I see. I still don't necessarily understand where Laravel's Service Providers and Containers come into play? Laravel really doesn't force you to use them for your own models/classes. Can you edit your question with some example of this and how you do it in Laravel? I'll be happy to answer when they are great and why use them and when it's not really necessary, but just give me some examples to work with. – DevK May 28 '18 at 00:37
  • 1
    When you enforce `Request` and provide `$request` data to your controller, then you have much more dependencies available, like validation, and more data in your controller functions upfront....BTW You name it, a framework convention and yes it is (What is wrong about that? That's how frameworks works...). Finally request object is much more useful in Laravel, than input object in CodeIgniter... – Bart May 28 '18 at 02:13
  • @devk thank you for your trying to help. As I'm a newbie in Laravel, I didn't know things that `@Bart` mentioned and I needed such an answer like that: Rather than coding style and convention, we have some kind of benefits only available in Laravel. As you said, maybe I should edit my question to... what are pros cons of loading resources in Laravel vs CodeIgniter? – Mohammad Naji May 28 '18 at 05:54

0 Answers0