【发布时间】:2020-04-03 09:04:27
【问题描述】:
我尝试从我的 index.blade.php 文件中的单个身份验证用户检索数据
<h3 class="profile-username text-center">{{$user ?? ''->lastname}}</h3>
使用我的 ProfileController
public function index($user){
$user_id = auth()->user()->id;
$user = User::findOrFail($user_id);
return view('profiles.index')->with('users',$user);
}
并且用户数据在我的 users 表中
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('accno')->unique();
$table->string('acc_type');
$table->string('firstname');
$table->string('middlename');
$table->string('lastname');
$table->string('address');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('phoneno')->unique();
$table->string('sex');
$table->string('martial_status');
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
和路线
Route::get('/profile/{user}', 'ProfilesController@index')->name('profiles.show');
我不断收到这个 Laravel 错误:
试图获取非对象的属性“姓氏”(查看:C:\Users\user pc\Desktop\dkn\resources\views\profiles\index.blade.php)。
【问题讨论】:
-
这是什么?
{{$user ?? ''->lastname}}.. 你的意思是$user->lastname? -
我在 index.blade.php 文件中回显 php