Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Laravel 5.4中尝试在OAuth2之后获取非对象的属性_Php_Laravel - Fatal编程技术网

Php 在Laravel 5.4中尝试在OAuth2之后获取非对象的属性

Php 在Laravel 5.4中尝试在OAuth2之后获取非对象的属性,php,laravel,Php,Laravel,我的一个foreach语句出错。这是在我将OAuth登录到我的项目之后发生的。问题是,一旦我发了一篇文章,一旦发了文章的人的名字,我就犯了这个错误,在我写OAuth之前,它一直工作得很好 搜索错误时,它会显示: ErrorException in 90b25bff626151e496cbeba41de0d0cc13613e1c.php line 90: The line 90 have: `<li><?php echo e($post->user->name);

我的一个
foreach
语句出错。这是在我将OAuth登录到我的项目之后发生的。问题是,一旦我发了一篇文章,一旦发了文章的人的名字,我就犯了这个错误,在我写OAuth之前,它一直工作得很好

搜索错误时,它会显示:

ErrorException in 90b25bff626151e496cbeba41de0d0cc13613e1c.php line 90:

The line 90 have: `<li><?php echo e($post->user->name); ?> &middot;</li>`
90B25BF626151E496CBEBA41DE0D0CC13613E1C.php第90行中的错误异常: 第90行有:`
  • ·` 这是我index.blade.php上的foreach

    @foreach ($posts as $post)
    
            <div class="col-sm-4 col-xs-12"> <!-- News -->
              <div class="thumbnail" onclick="location.href='{{ url('news/'.$post->slug) }}';">
                <div class="imageWrapper">
                  <img src="{{ asset('imags/' . $post->postimg) }}" alt="feature-collection-image">
                  <!-- <div class="masking"><a href="{{ url('news/'.$post->slug) }}" class="btn viewBtn">Leer Artículo</a></div> -->
                </div>
                <ul class="list-inline post-author">
                  <li>{{ $post->user->name }} &middot;</li>
                  <li><span class="badge">{{ $post->comments()->count() }}</span> comentarios</li>
                </ul>
                <div class="caption post-info">
                  <h4>{{ substr($post->title, 0, 150) }}{{ strlen($post->title) > 150 ? "..." : "" }}</h4>
                  <p>
                    {{ substr(strip_tags($post->body), 0, 200) }}{{ strlen(strip_tags($post->body)) > 200 ? ". Leer más" : "" }}
                  </p>
                </div>
              </div>
            </div>
    
            @endforeach
    
    @foreach($posts as$post)
    postimg)}“alt=”功能集合图像“>
    
    • {{$post->user->name}}·
    • {{$post->comments()->count()}}
    {{substr($post->title,0150)}{{strlen($post->title)>150?…“:”} {{substr(strip_tags($post->body),0200)}{{strlen(strip_tags($post->body))>200?.Leer más:“}”

    @endforeach
    在OAuth之前,它工作得很好,文章创建者的名字和我的新闻/单曲上的帖子都显示得很完美,但是现在

    我不知道会发生什么


    PD:如果我删除
    {{$post->user->name}
    一切正常,但它不会显示post创建者的名称,我会将OAuth配置放在我的LoginController和Config/Services.php上。

    现在运行良好,我认为这是一次错误的迁移

    我做了一个新的表格,叫做社交网络

    public function up()
    {
        Schema::create('social_providers', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned()->references('id')->on('users');
    
            $table->string('provider_id');
            $table->string('provider');
            $table->timestamps();
        });
    }
    
    我所做的是回滚所有迁移,并将其更改为:

    public function up()
    {
        Schema::create('social_providers', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users');
            $table->string('provider_id');
            $table->string('provider');
            $table->timestamps();
        });
    }
    

    再次运行我的服务器“php artisan serve”“创建新管理员、新用户和新帖子。”。。现在正在工作,但我不确定这是否是问题所在。

    您是否有任何用户密钥与用户不匹配的帖子?您的错误表明它无法找到链中的
    用户
    部分。随后它无法检索名称。在管理仪表板和posts/show“where i can see the posts list”上,名称显示正确,但现在在index和news/single上,我无法。。不知道为什么如果它在一页上起作用,而在另一页上不起作用,那么你一定在做不同的事情。查看如何在控制器中检索它以及如何显示它。一定有什么不同