dimanche 24 juillet 2016

Trying to implement Repository Pattern in Laravel 5.2

Controller class

class SportsTypeController extends \App\Http\Controllers\BaseController
{
    private $sportstype;

    public function __construct(ISportsType $_sportstype) {
        $this->sportstype = $_sportstype;
        parent::__construct();
    }

    public function index() {
        $SportsTypes = $this->sportstype->All();
        return view('SportsType.List')->with('SportsTypes', $SportsTypes);
    }
}

Business logic class

class SportsTypeBL implements ISportsType {       

    public function All() {
        $SportsTypes = (new SportsTypeDb())->All();
        return $SportsTypes;
    }
}

Database class

class SportsTypeDb {

    public function All() {
        $SportsTypes = \App\Models\SportsType\SportsTypeModel::all();
        return $SportsTypes;
    }
}

Interface

public interface ISportsType {
     public function All();
}

Am I writing bad or very bad code? Can you please suggest good ways to improve it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire