php - 试图在 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');
}
}
但是我在这里没有发现任何问题。关于如何修复它的任何建议?如果您需要代码中的其他内容,请告诉我,我不知道我还应该给您什么,以便您帮助我。提前致谢!
解决方案
试试这个 ..
{{dd($user)}}
如果你有财产name
,那么你可以像这样打电话..
{{$user['name']}}
把它当作数组而不是对象
推荐阅读
- java - Arrays.sort 和 parallelsort 之间的区别
- java - 如何将一张大地图分成几张小地图?
- c# - 如何根据数据库值检索或启用单选按钮?
- python - 如何在json文件中查找和替换值的一部分
- javascript - 我的编辑按钮的 ajax 不起作用
- python - 如何从机器人框架的列表中删除项目?
- java - 我需要在下拉框内滚动
- sql-server - UPDATE STATISTICS 返回错误“表不存在”。在 SQL Server 中
- asp.net - 我们可以将 asp.net 网站容器化吗?但是在 vs 2017 中没有这个选项
- java - 如何在 Spring 工具套件 (STS) 中删除 application.properties 的错误通知