@bugsysha
Getting the following error
"Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::brand()"
I have the relationship set up in the product model and the brand model.
// Product.php model
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
class Product extends Model
{
public function brand()
{
return $this->belongsTo(Brand::class);
}
}
// Brand.php model
namespace App;
use Illuminate\Database\Eloquent\Model;
class Brand extends Model
{
public function product()
{
return $this->hasMany(Product::class);
}
}
Also, I'm throwing in the category model as well
// Category.php model
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
public function parent()
{
return $this->belongsTo(self::class, 'parent_id');
}
public function children()
{
return $this->hasMany(self::class, 'parent_id', 'id');
}
public function products()
{
return $this->hasMany(Product::class);
}
}
Its late is it a typo? Although I made it work with the leftJoin() if it is better with the relationship (performance-wise) I would like to make it work that way.
Thanks for your time ;)