首页 > 解决方案 > 试图在 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 Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

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');
    }
}

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

标签: phplaravel

解决方案


试试这个 ..

{{dd($user)}}

如果你有财产name ,那么你可以像这样打电话..

{{$user['name']}}

把它当作数组而不是对象


推荐阅读