Support the ongoing development of Laravel.io →
IOC Architecture
Last updated 1 year ago.
0

Hi behnampmdg3,

At first you would need to separate the business logic and the design logic. Observing your code the first thing would be made extract your HTML code to the views folder using two options: a) layouts, b) layouts + partial layouts (in example navbar.blade.php, sidebar.blade.php, widgets.blade.php, maincontent.blade.php, footer.blade.php, and so much)

Later you use BLADE to populate the view with the variables sent by the Controllers to the Views using the content of the Models.

If you need more business logic you can create in the APP folder a subfolder with these logic classes, but remember add to the composer.json autoload section using any of the class mapping options.

Hope it helps you.

Last updated 1 year ago.
0

I realise the best way is to understand Dependency Injection first

Can you tell me if this is the right approach?


$payment_method = new credit_card_payment();
$object = new process_payment($payment_method);
echo $object->execute(2);


#Classes, interfaces and Jesus

interface payment_service
    {
        public function payment_option($details);
    }

class credit_card_payment implements payment_service
    {
        public function payment_option($details)
            {
                echo "CC method";
            }
    }

class paypal_payment implements payment_service
    {
        public function payment_option($details)
            {
                echo "Paypal method";
            }
    }    

class process_payment
    {
        private $payment_method;

        public function __construct(payment_service $payment_service)
            {
                $this->payment_method = $payment_service;
            }

        public function execute($details)
            {
                return $this->payment_method->payment_option($details);
            }    
    } 

I don't like the fact that I have to write this $payment_method = new credit_card_payment();

I am reading on PHP-DI container now.

It seems like a very simple concept BUT IT'S NOT.

Thanks

Last updated 1 year ago.
0

See the IoC concept in Laravel:

http://laravel.com/docs/ioc

Here you can find some features that could be useful for you.

Hope it helps you.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.