freevital / laravel-repository Goto Github PK
View Code? Open in Web Editor NEWLaravel Repositories to abstract the database layer
License: MIT License
Laravel Repositories to abstract the database layer
License: MIT License
Is this compatible with laravel 5.4?
If I inject BRepo in ARepo, how to inject ARepo in BRepo?
This is my BRepo
class BRepository extends BaseRepository
{
/**
* @var ARepository
*/
private $aRepo;
/**
* @param Application $app
* @param ARepository $aRepo
*/
public function __construct(Application $app, ARepository $aRepo)
{
parent::__construct($app);
$this->aRepo = $aRepo;
}
}
This is my ARepo
class ARepository extends BaseRepository
{
/**
* @var BRepository
*/
private $bRepo;
/**
* @param Application $app
* @param BRepository $bRepo
*/
public function __construct(Application $app, BRepository $bRepo)
{
parent::__construct($app);
$this->bRepo = $bRepo;
}
}
I get Http Error 500, "domain.com is currently unable to handle this request", for all routing that use ARepository or BRepository class. I can inject ARepository with all other repositories with no problem except for BRepository class. Thanks in advance.
class ARepository extends BaseRepository {
public function model()
{
return "App\Models\A";
}
public function createNewA(){
DB::beginTransaction();
try{
$this->model->create([
'column_a' => 'test'
]);
DB::commit();
}catch(Exception $e){
DB::rollback();
}
}
}
How to call function createNewA() in another repo? I tried this but it did not work
class BRepository extends BaseRepository {
protected $aRepo;
public function model()
{
return "App\Models\B";
}
public function createNewB(){
$this->aRepo = new ARepository();
DB::beginTransaction();
try{
$this->aRepo->createNewA();
$this->model->create([
'column_b' => 'test'
]);
DB::commit();
}catch(Exception $e){
DB::rollback();
}
}
}
This is the controller
class HomeController extends Controller
{
protected $repo;
public function __construct(BRepository $repo)
{
$this->repo = $repo;
$this->repo->createNewB();
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.