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;
}