seyidaniels
1 year ago
124
3
Laravel

Blade Template Error Trying to get property of non-object

Posted 1 year 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.

@extends('layouts/master')

@section('title') The Dashboard @endsection

@include('includes.header')

@section('content')

The Dashboard

@include('includes.messageblock')

    <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>
        </div>
        <button type="submit" class="btn btn-info btn-fill btn-md pull-right">Post!</button>
        <input type="hidden" name="_token" value="{{Session::token()}}">
    </form>
</div>
</div>

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>
                @endif
                </div>
            </article>
            <div style="margin-top: 15px;"></div>
    @endforeach
</div>

    
    
</div>
×

Edit Post

    <div class="form-group">
        <textarea class="form-control" id="editcontent" name="body" id="newpost" rows="3" ></textarea>
    </div>
    
  </div>
  <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>
  </div>
</div>
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.