TheBAST
TheBAST

Reputation: 2736

laravel undefined property (repository)

I don't know why I'm getting this error:

Undefined property: App\Repositories\Admin\MedicineRepository::$getMedicineInformation

when I'm just dd-ing the result value

MedicineCOntroller.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Repositories\Admin\MedicineRepository;
use App\Http\Requests;
use App\Dosage;

class MedicineController extends Controller
{
    public function __construct(MedicineRepository $MedicineRepository)
    {
        $this->MedicineRepository = $MedicineRepository;
    }

    public function getMedicine()
    {
        $medicine = $this->MedicineRepository->getMedicineInformation;
        dd($medicine);
        //return view('admin.show-medicines',compact('dosage'));
    }
}

MedicineRepository.php

<?php
namespace App\Repositories\Admin;
use App\Medicine,
App\Dosage;

class MedicineRepository 
{

    public function __construct(Medicine $medicine, Dosage $dosage){
        $this->medicine = $medicine;
        $this->dosage = $dosage;
    }

    public function getMedicineInformation()
    {
        return $medicine
        ->join($this->dosage,'medicines.id' ,'=', 'dosages.medicine_id')
        ->select('generic_name','dosages.dosage_name');
    }






}

Upvotes: 0

Views: 1851

Answers (2)

Vikash
Vikash

Reputation: 3561

You are tying to call the method without parenthesis. You can call variables like this not method

try this

 $this->MedicineRepository->getMedicineInformation();

Upvotes: 0

Alexey Mezenin
Alexey Mezenin

Reputation: 163838

Since getMedicineInformation() is a method, you should call it:

 $this->MedicineRepository->getMedicineInformation();

Upvotes: 2

Related Questions