私はLaravelフレームワークでWebアプリケーションを作成しており、ユーザーの特定のデータを取得する際に問題が発生しています。私のWebアプリケーションのユーザ構造は、メインユーザテーブルに基づいており、健康、エネルギー、自分が所有するアイテムなどのすべてのユーザ統計のRPテーブルを持っています。Laravel:非オブジェクトのプロパティを取得しようとしています
私は次のようなエラーに
Trying to get property of non-object (View: C:\workspace\mainwebsite\resources\views\frontend\home.blade.php)
Oは、単にユーザーのためのロールプレイテーブルのuser_idの列をプリントアウトしてみました(はい、私を受け付けております上、このデータを表示しようとしているページを訪問
<?php
namespace App\Database\Website\User;
use Hash;
use Eloquent;
use \Illuminate\Auth\Authenticatable;
use \Illuminate\Contracts\Auth\Authenticatable as Authentication;
class Player extends Eloquent implements Authentication
{
use Authenticatable;
protected $primaryKey = 'id';
protected $table = 'users';
public $timestamps = false;
protected $fillable = [];
public function setPasswordAttribute($value)
{
$this->attributes['password'] = Hash::make($value);
}
public function setUsernameAttribute($value)
{
return $this->attributes['username'] = $value;
}
public function roleplay()
{
return $this->hasOne('App\Database\Website\User\Roleplay', 'user_id');
}
}
:ここ
<div class="panel panel-default">
<div class="panel-body">
{{ Auth::user()->roleplay->user_id }}
</div>
</div>
は私のユーザー・テーブル・クラスである)他の列彼らは出力と同じ結果を試みていますここ
は私のロールプレイテーブルクラスです:
<?php
namespace App\Database\Website\User;
use Eloquent;
class Roleplay extends Eloquent
{
protected $primaryKey = 'id';
protected $table = 'srp_user_statistics';
public $timestamps = false;
protected $fillable = ['user_id'];
public function user()
{
return $this->belongsTo('App\Database\Website\User\Player', 'user_id', 'id');
}
}
私はすでに、私はちょうど認証からデータを取得することができますので、私が認証しています知っている::ユーザー() –
、エラーが発生したライン上を得ていますか? –