Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rajan001's avatar

Property [kriyakalap] does not exist on this collection instance.

I wanted to fetch data by comparing some data but i got an error Property does not exists. I don't know where i am wrong.

Controller

public function SchoolReportToAdmin()
    {
        $biniyojan = BiniyojanDetails::get();
        $school_data = school_bini::where('kriyakalap', $biniyojan->kriyakalap)->get();
        dd($school_data);

        return view('schoolDataToAdmin');
    }

BiniyojanDetails Table columns

`details_id`, `biniyojan_id`, `school`, `school_id`, `source`, `kriyakalap`, `debit_credit`, `debit_credit_type`, `rev_kriyakalap`, `rev_debit_credit_type`, `cash`, `rev_cash`, `created_at`, `updated_at`

school_bini Table columns

 `id`, `school_id`, `date`, `ab`, `behora`, `kriyakalap`, `debit_credit`, `debit_credit_type`, `sub_topic`, `summary`, `cash`, `completed`, `created_at`, `updated_at`

Even dd() shows same error

0 likes
17 replies
Sinnbeck's avatar

This gets every single row in your database

$biniyojan = BiniyojanDetails::get();

So you cannot get a property of it like that. Get one item maybe? I'm not sure what you are trying to do so it's hard to give advice

rajan001's avatar

@Sinnbeck Basically I wanted to fetch value from school_bini table by comparing Kriyakalap which is also included in BiniyojanDetails table.

Sinnbeck's avatar

@rajan001 so you want to compare every single kriyakalap from the first query in the second query? Or one specific?

If you want to compare all of them, you should use a relationship

$school_data = school_bini::has('biniyojanDetails')->get();
        dd($school_data);
Sinnbeck's avatar

@rajan001 then use a relationship or a join (unless BiniyojanDetails only has like 10 rows or something)

Sinnbeck's avatar

@rajan001 one of

$biniyojan = BiniyojanDetails::first();//first record 
        $school_data = school_bini::where('kriyakalap', $biniyojan->kriyakalap)->get();
        dd($school_data);

//or
$biniyojan = BiniyojanDetails::find(32); //get specific record 
        $school_data = school_bini::where('kriyakalap', $biniyojan->kriyakalap)->get();
        dd($school_data);
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Or in theory if you have few records in the first query

$biniyojan = BiniyojanDetails::pluck('kriyakalap');
        $school_data = school_bini::whereIn('kriyakalap', $biniyojan)->get();
        dd($school_data);
Shivamyadav's avatar

@rajan001 Yo can use it just like this

$biniyojan = BiniyojanDetails::get['kriyakalap', 'id'];
        $school_data = school_bini::whereIn('kriyakalap', $biniyojan->kriyakalap)->get();
        dd($school_data);

rajan001's avatar

@Sinnbeck @shivamyadav i have tried this method and got the result but it only gets first value but i want to all. When i use get() error is same.

public function SchoolReportToAdmin()
    {
        $biniyojan = BiniyojanDetails::first('kriyakalap','school_id');
        $school_data = school_bini::where(['kriyakalap' => $biniyojan->kriyakalap],['school_id' => $biniyojan->school_id])->get();
        dd($school_data);
        return view('schoolDataToAdmin',compact('school_data'));
    }
SilenceBringer's avatar

@rajan001 try this

	public function SchoolReportToAdmin()
    {
        $biniyojan = BiniyojanDetails::get();
        $school_data = school_bini::whereIn('kriyakalap', $biniyojan->pluck('kriyakalap'))
			->whereIn('school_id', $biniyojan->pluck('school_id'))
			->get();
        dd($school_data);
        return view('schoolDataToAdmin',compact('school_data'));
    }
1 like
rajan001's avatar

@Sinnbeck yes thanks. I have one more condition in same code. I also want to fetch data from relation table but I'm getting same type of error for database relation 'Property [school_bini_tax] does not exist on this collection instance.' I have added with condition

    public function SchoolReportToAdmin()
    {
        $biniyojan = BiniyojanDetails::get();
        $school_data = school_bini::with('school_bini_tax')
            ->whereIn('kriyakalap', $biniyojan->pluck('kriyakalap'))
            ->whereIn('school_id', $biniyojan->pluck('school_id'))
            ->get();
        dd($school_data->school_bini_tax);
        return view('schoolDataToAdmin', compact('school_data'));
    }

sch_bini Relation Table

public function sch_bini(): BelongsTo
    {
        return $this->belongsTo(school_bini::class, 'id', 'sch_bini_id');
    }

school_bini_tax relation table

public function school_bini_tax(): HasMany
    {
        return $this->hasMany(School_bini_tax::class, 'sch_bini_id', 'id');
    }
Sinnbeck's avatar

@rajan001 Same problem again. Can I suggest watching the "Laravel 8 from scratch" videos? I can see you have some confusion with getting multiple items, and just 1.

You are again getting multiple items, so to get a column for all items

dd($school_data->pluck('school_bini_tax'));
1 like

Please or to participate in this conversation.