Skip to content

Instantly share code, notes, and snippets.

@alkrauss48
Last active April 15, 2022 17:31
Show Gist options
  • Save alkrauss48/0079cc8f1b675b3c166d9e0664ee1e93 to your computer and use it in GitHub Desktop.
Save alkrauss48/0079cc8f1b675b3c166d9e0664ee1e93 to your computer and use it in GitHub Desktop.
laravel-interview-scenario
<?php
public function list_blog_posts(Request $request)
{
$posts = BlogPost::where(
DB::raw("status = '" . $request->input('status') . "'")
)->get();
$posts = $posts->filter(function($value, $key) {
return $value->isPublished();
});
return response()->json(
$posts->map(function($post) {
return [
'title' => $post->title,
'status' => $post->status,
'author' => [
'name' => $post->author->name
]
];
})
);
}
@alkrauss48
Copy link
Author

Note: There are no syntax errors, and you can assume that this code will properly run as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment