jeudi 17 mars 2016

Why create a facade in laravel instead of calling a method directly?

I'm just starting with laravel and want to understand this...

Lets say we have a class in our application:

namespace App\Tests;
class MyTest{

    public function sayHello($name){
        echo "Hello, $name!";
    }

    public static function anotherTest(){
        echo "another test...";
    }

}

What is the advantage of creating a facade and a service provider over just using it as

use App\Tests\MyTest;

//... controller declarations here ....

public function someaction(){

    $mt = new MyTest();
    $mt->sayHello('John');

    //or
    MyTest::anotherTest();

}

//... etc...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire