试图获取非对象的属性(查看:C:\ xampp \ htdocs \ Investipediaa \ resources \ views \ frontend \ layouts \ Profile.blade.php)

时间:2017-04-13 19:17:56

标签: database laravel views controllers

我在视图中收到此错误,我的查看源代码就在这里。一切正常,但突然间我收到此错误,无法找到问题发生的位置。

数据库用户常规和帖子中有三个表我想在此配置文件视图中检索经过身份验证的用户的数据但是获得此异常。我将非常感谢堆栈溢出成员为我提供解决方案。

 <div class="panel panel-danger">
                {{--<div class="panel-heading">--}}
                {{--Danger Panel--}}
                {{--</div>--}}
                <div class="panel-body">
                    <blockquote class="col-md-3">
                        <img style="width:210px ; height: 230px " src="{{url('user.png')}}">

                        <h2>{{$user2['username']}}</h2>


                    </blockquote>
                    <div class="well col-md-9 details">


                        <h4>Email : {{$user1['email']}}</h4>
                        <h3>Phone No: {{$user2['phone_number']}}</h3>
                        <h4>Gender: {{$user2['gender']}}</h4>
                        <h4>Country: {{$user2['country']}}</h4>


                    </div>

                </div>
                {{--<div class="panel-footer">--}}
                {{--Panel Footer--}}
                {{--</div>--}}
            </div>
            <div class="panel panel-danger">
                {{--<div class="panel-heading">--}}
                {{--Danger Panel--}}
                {{--</div>--}}
                <div class="panel-body">
                    @foreach($posts as $post)
                        <blockquote class="col-md-3">
                            <p>{{ $post->body }}</p>
                            <div class="info">
                                Posted by <h4>{{$post->user->email}} </h4>on {{$post->created_at}}
                            </div>
                            <div class="interaction">
                                <a href="#">Like</a> |
                                <a href="#">Dislike</a>
                                @if(Auth::user() == $post->user)
                                    |<a href="#">Edit</a> |
                                    <a href="{{route('post.delete',['post_id' => $post->id])}}">Delete</a>
                            @endif

                        </blockquote>
                    @endforeach

我的控制器功能用于检索数据。这里我从3个数据库表中访问经过身份验证的用户的数据。

public function userProfile()     {

    $user_id = Auth::user()->id;
    $user1 = User::where('id',$user_id)->first();
    $user2 = Regular::where('user_id',$user_id)->first();
    $posts = Post::where('id',$user_id)->first();
    return view('frontend.layouts.Profile',compact('user1','user2','posts'));
}

0 个答案:

没有答案