Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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
未签名时,ErrorException-尝试获取非对象的属性(视图:C:\xampp\…\show solo.blade.php)_Php_Laravel_Laravel 5.4 - Fatal编程技术网

未签名时,ErrorException-尝试获取非对象的属性(视图:C:\xampp\…\show solo.blade.php)

未签名时,ErrorException-尝试获取非对象的属性(视图:C:\xampp\…\show solo.blade.php),php,laravel,laravel-5.4,Php,Laravel,Laravel 5.4,大家好,我只是想问一下关于拉雷维尔的情况,以供像我这样的学习型学生使用 登录后,我可以访问此页面: Route::get('/posts/{id}', 'PostController@showById'); 当我注销并再次尝试访问该页面时,我收到了上面提到的错误,我希望即使是为来宾显示帖子,但如果他们注销,则不允许撰写帖子 这是showById(): 还有show-solo.blade.php @extends('master') @include('partials.nav-none')

大家好,我只是想问一下关于拉雷维尔的情况,以供像我这样的学习型学生使用

登录后,我可以访问此页面:

Route::get('/posts/{id}', 'PostController@showById');
当我注销并再次尝试访问该页面时,我收到了上面提到的错误,我希望即使是为来宾显示帖子,但如果他们注销,则不允许撰写帖子

这是showById():

还有show-solo.blade.php

@extends('master')

@include('partials.nav-none')

@section('content')
    <div class="col-sm-8 blog-main">
        <div class="blog-post">

            @if ($flash = session('message'))
                <div class="alert alert-success flash-message" role="alert">
                    {{ $flash }}
                </div>
            @endif

            @if ( $post->user_id  == Auth::user()->id)
                <a href="/posts/{{ $post->id }}/delete">
                    <button class="btn-sm btn-warning post-btn" data-toggle="tooltip" data-placement="top" title="Delete Post"><i class="fa fa-times"></i></button>
                </a>
                <a href="/posts/{{ $post->id }}/edit">
                    <button class="btn-sm btn-primary post-btn" data-toggle="tooltip" data-placement="top" title="Edit Post"><i class="fa fa-pencil-square-o"></i></button>
                </a>
            @endif          

            <h2>Post number: {{ $post->id }}</h2>

            <h2 class="blog-post-title">
                <a class="title-link" href="/posts/{{ $post->id }}">{{ $post->title }}</a>
            </h2>

            <!-- {{ $post->created_at->toFormattedDateString() }} -->
            <p class="blog-post-meta">{{ $post->created_at->diffForHumans() }} by <a href="#">{{ $post->user->name }}</a></p>
            {{ $post->body }}

            <hr />

            @include('partials.error')

            @include('partials.post-comment')
        </div>
    </div>
@endsection
我做错什么了吗?为什么即使我是客人也不能访问/posts/{id}?“尝试获取非对象的属性”消息意味着什么

请告诉我,我是否应该在这里引用一些代码来帮助解决这个问题


如有任何建议,将不胜感激。谢谢。

您在下一行中看到了错误

@if ( $post->user_id  == Auth::user()->id)
在视图中

这一行出现错误的原因是您试图访问经过身份验证的用户的id,例如,
Auth::user()->id
。但是没有经过身份验证的用户。因此,
Auth::user()
调用返回
null
。您正试图在
null
上访问
id

试着把它改成

@if ( $post->user_id  == @Auth::user()->id)


这对我来说是一个诀窍“@if($post->user_id==@Auth::user()->id)”,我能问一下我的处境中发生了什么吗?更多信息,我对发生的事情有点执着。请看我更新的答案。我希望这能消除你的疑虑。我接受了答案,不知道为什么没有通过。再次感谢。
@if ( $post->user_id  == Auth::user()->id)
@if ( $post->user_id  == @Auth::user()->id)
@if(Auth::user())
    @if ( $post->user_id  == Auth::user()->id)
    ...
    @endif
@endif