Ich versuche Eloquent zu verwenden, um ein bestimmtes Produkt zu erhalten, das eine brand_id
-Spalte hat, die auf eine brands
-Tabelle abbildet, die brand
-Array wird leer zurückkommen.Laravel Eloquent mit() -> null zurück
Gibt es hier etwas, das offensichtlich geändert werden muss?
$product = Product::with('images')->with('brand')->select($fields)->where('display', '=', 1)->find($id);
// Produktmodell
class Product extends Eloquent {
...
public function brand()
{
return $this->belongsTo('Brand');
}
// Marke Modell
class Brand extends Eloquent {
...
public function products()
{
return $this->hasMany('Product');
}
haben Sie es überprüft mit: $ brand = $ product-> brand(); ? – num8er
Welche Felder befinden sich in der Variablen '$ fields'? –