I am not much experienced in Laravel and facing some strange issues. I have been working on a simple project. In my local development environment where I use xampp on windows, the website works perfectly well but after uploading the project to the live server some of the relations do not work properly or I should say they behave in a very strange way.

The below block of code returns error: 'trying to get property from non object' in my case.

@foreach($transactions as $transaction)
  <td>{{$transaction->Methodtype->name}}</td>
  <td>{{$transaction->Gateway->name}}</td>
@endforeach

My controller file includes the below

public function transactions() {
    $transactions = Transaction::where(['trxndeleted' => '0'])->get();
    return view('layouts.pages.transactions', compact('transactions'));
}

However when I return results directly to check then I get required data. Please see below.

public function transactions() {
    $transactions = Transaction::where(['trxndeleted' => '0'])->get();
    return $transactions[0]->Methodtype;
}

My Transaction and Methodtype models look like below

Transaction Model:

public function Methodtype() {
    return $this->belongsTo('App\methodtype', 'methodtype_id');
}

Methodtype Model:

public function Transaction() {
    return $this->hasMany('App\Transaction', 'methodtype_id');
}
0

There are 0 best solutions below