2 years ago

Blade Template Error Trying to get property of non-object

Posted 2 years ago by seyidaniels

I recently got an error with my dashboard blade template which i didn't edit and i do not seem to understand this error. Although i realized the errors came from the article html tag where am calling the posts variable i passed from my controller class, i do not know how to solve this problem.


@section('title') The Dashboard @endsection



The Dashboard


    <div class="col-md-6 col-md-offset-3">
    <form action="{{route('post.create')}}" method="post">
        <p class="lead">Update status</p>
        <div class="form-group">
        <textarea class="form-control" name="body" id="newpost" rows="3" placeholder="What's on your mind?"></textarea>
        <button type="submit" class="btn btn-info btn-fill btn-md pull-right">Post!</button>
        <input type="hidden" name="_token" value="{{Session::token()}}">

What Others are saying

    @foreach($posts as $post)
            <article class="posts" data-id="{{$post->id}}">
                <p id="body">{{$post->body}}</p>
                <div class="info pull-right">Posted by {{$post->user->name}} on {{$post->created_at}}</div>
                <div class="interaction">
                    <a href="#">Like</a>
                    <a href="#">Dislike</a>
                @if(Auth::user() == $post->user)
                    <a href="#" class="edit">Edit</a>
                    <a href="{{route('post.delete',['post_id' => $post->id])}}">Delete</a>
            <div style="margin-top: 15px;"></div>


Edit Post

    <div class="form-group">
        <textarea class="form-control" id="editcontent" name="body" id="newpost" rows="3" ></textarea>
  <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal" >Close</button>
    <button type="button" class="btn btn-primary" id="save">Save changes</button>
var token = "{{Session::token()}}" var url = "{{route('edit')}}"; @endsection

post controller class

public function getDashboard(){
    $posts = Post::orderBy('created_at', 'desc')->get();
    return view('dashboard', ['posts' => $posts]);

Please sign in or create an account to participate in this conversation.