jeudi 4 mai 2017

Trying to get property of non-object error in laravel

ive been trying to match User_id from my users with Creator_id to display the creators username in my post but im getting the trying to get property from non-object error and i cant get arround it

the function in my controller postcontroller.php:

public function index()
    {
    $allusers = users::getusers();

    $posts = DB::table('posts')->get();
    foreach ($posts as $posts) {
        foreach ($allusers as $allusers) {
            if ($posts->creator_id == $allusers->user_id) {
              array_push($posts,$allusers->username); 
            }
        }
    }
     return view('blog',['posts'=>$posts]);   
    }

the functions in my model:

public static function getusers(){
    $allusers = users::all();
    return $allusers;
    }



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2pInRqE
via IFTTT

Aucun commentaire:

Enregistrer un commentaire