lundi 25 septembre 2017

Trying to get property of non-object while reaching prents attribute

I got Trying to get property of non-object error on line: <span></span>. How can I reach name of a subcat of a product? my Product model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $guarded=[];

    public function subcats(){
        return $this->belongsTo(Subcat::class);
    }

    public function comments(){
        return $this->hasMany(Comment::class);
    }
}
my Subcat Model:
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Subcat extends Model
{
    protected $guarded=[];

    public function cats(){
        return $this->belongsTo(Cat::class);
    }

    public function products(){
        return $this->hasMany(Product::class);
    }
}
the blade is:
@extends('template.master')
@section('content')

        @forelse($product as $item)
            <div class="col-lg-4">
                <a href="/product/"></a><br>
                <span class="caret"></span><br><br>
                <span>Price :</span><span class="caret"></span><br>
                
                 <span></span> 
            </div>
        @empty
        @endforelse
@endsection



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2xvFDRF
via IFTTT

Aucun commentaire:

Enregistrer un commentaire