Coder Social home page Coder Social logo

freevital / laravel-repository Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 1.0 17 KB

Laravel Repositories to abstract the database layer

License: MIT License

PHP 100.00%
laravel laravel-repositories repositories eloquent laravel-models database-layer laravel-repository

laravel-repository's People

Contributors

freevital avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

hubmee

laravel-repository's Issues

Injecting 2 repositories

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.

How to call function in repository from another repository

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();
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.