私はすでにいくつかのことを試みましたが、これを動作させることはできません。belongsTo()はユーザーのリレーションシップを返しません
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
public $timestamps = false;
protected $table = 'users';
protected $fillable = ['id_city', 'name', 'email', 'password', 'admin'];
protected $hidden = ['password', 'remember_token'];
public function city()
{
return $this->belongsTo('App\City');
}
}
そして、これが私の市のモデルである:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class City extends Model
{
public $timestamps = false;
protected $table = 'cities';
protected $fillable = ['name', 'slug'];
public function users(){
return $this->hasMany('App\User');
}
}
そして、私は私の上{{ $user->city->name }}
を使用しようとしている私は、この{{ $user->city->name }}
私のユーザモデルのようなものを作ることができるようにしたいです表示されても動作しない場合は、エラーを返します。ErrorException:非オブジェクト(View:.../views/app/text.blade.php)のプロパティを取得しようとしています。
どうすればよいですか?
は '' User'クラスのuser'ですか? '都市 'はその名前の機能の呼び出しであることを意味していますか?それから、それが必要です。私たちに[mcve]を与えるのはどうですか?それでは、何が起こっているのかを把握するために質問をし続ける必要はありません。私たちは自分自身のためにそれを見ることができます。 –