Reputation: 285
I am trying to get the values from other table but i am getting this error My Model loo like this:
class PageList extends Model
{
protected $table = 'page_master';
protected $fillable = ['business_id', 'page_url', 'page_name'];
public function particulars()
{
return $this->hasOne('App\Sale','id');
}
}
and my blade template is:
<p>{{$value->particulars->regular_price}}</p>
I want to get value from page_particulars table and the value is regular_price but i am getting error of trying to get property of non-object. Where i am doing wrong? Any help will be highly appreciated!
public function pageListHere()
{
$list = PageList::all();
return view('page-list',compact('list'));
}
Upvotes: 1
Views: 501
Reputation: 9853
use optional()
helper method
<p>{{optional($value->particulars)->regular_price}}</p>
Upvotes: 1
Reputation: 9381
You compact('list')
not compact($list)
which will not pass the collection result you are expecting, but just a string.
Next to that
public function particulars()
seems not to return an object for this $value
which. So the result might be null
Upvotes: 0