Update PostsController.php

I changed the source code completely because the original code wasn't working