ich dieses Modell verwenden, aber dieses Modell zeigt unten Fehler verwenden:Zugang zu belongsTo Verfahren in demselben Modell Laravel
Failed calling App\User::jsonSerialize()
aber entfernen „$ this-> kunden-> name“ Ergebnis in Ordnung ist. thankssssssssssssssssssssssssssssssssssssssssssssssssssssssssss.
class User extends Authenticatable
{
/**
* Get the user's customer name.
*
* @param string $value
* @return array
*/
public function getCustomerIdAttribute($value)
{
return [
'id' => $value,
'name' => $this->customer->name
];
}
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [
'customer_id' => 'array',
];
/**
* Get the customer record associated with the user.
*/
public function customer()
{
return $this->belongsTo(Customer::class);
}
}
$ user = Auth :: Benutzer(); Rückgabe $ Benutzer; – HassanDL