php - Trying to get property of non object Laravel 5.2 -


the error occurs when print messages logged in user sent others him. did var_dump in controller in view. did {{$threads->count()}} in view , showed 27(thread count). when access view file throws me above mentioned error.

here controller code

public function index() {     $currentuserid = auth::user()->id;     $threads = thread::getalllatest()->get();     return view('chatindex', compact('threads', 'currentuserid')); } 

i printed currentuserid in view , works fine

here view code (where error occurs)

@extends('layouts.app')  @section('content')    @if (session::has('error_message'))         <div class="alert alert-danger" role="alert">             {!! session::get('error_message') !!}         </div>     @endif     @if($threads->count() > 0)         @foreach($threads $thread)         <?php $class = $thread->isunread($currentuserid) ? 'alert-info' : ''; ?>         <div class="media alert {!!$class!!}">             <h4 class="media-heading">{!! link_to('messages/' . $thread->id, $thread->subject) !!}</h4>             <p>{!! $thread->latestmessage->body !!}</p>             <p><small><strong>creator:</strong> {!! $thread->creator()->name !!}</small></p>             <p><small><strong>participants:</strong> {!! $thread->participantsstring(auth::id()) !!}</small></p>         </div>         @endforeach     @else         <p>sorry, no threads.</p>     @endif @stop  

it throws me error trying property of non-object (view: c:\xampp\htdocs\laravel-projects\user_prof\resources\views\chatindex.blade.php)

maybe in foreach $thread array() use 1 as

 $thread['id'], $thread['subject'] 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -