尝试在Laravel中获取非对象的属性"名称"(视图:D:\...\resources\views\home.blade.php



我这里有一个小问题,我猜代码没有得到正确的名称形式...... 这是它向我展示错误的地方:

<div class="rank-label-container">
<span class="label label-default rank-label">{{$user ?? ''->name}}</span>
</div>

有人试图说服我,我的错误就在create_user_table

<?php
use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('avatar')->default('user.jpg');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}

但我在这里没有发现任何问题。 关于如何解决它的任何建议? 如果您需要代码中的其他内容,请告诉我,我不知道我应该给您什么,以便您可以帮助我。 提前感谢!

试试这个..

{{dd($user)}}

如果你加特财产name然后你可以这样打电话..

{{$user['name']}}

将其作为数组而不是对象获取

试试这个,我相信它会起作用 {{$user->名称}} 或 {{$user['name']}}

相关内容

最新更新