Skip to content
Advertisement

Trying to get property ‘name’ of non-object in Laravel (View: D:…resourcesviewshome.blade.php

I have this little problem here where the code isn’t getting the proper form of the name I guess… This is the place where it shows me a mistake:

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

Someone tried to convince me that my mistake is here in the 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');
    }
}

But I didn’t find any problem in here. Any suggestions on how to fix it? And if you need something else from the code tell me please, I didn’t know what else should I give you so you can help me. Thanks in advance!

Advertisement

Answer

Try this, i sure it will work {{$user->name}} Or {{$user[‘name’]}}

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement