Last active
April 15, 2022 17:31
-
-
Save alkrauss48/0079cc8f1b675b3c166d9e0664ee1e93 to your computer and use it in GitHub Desktop.
laravel-interview-scenario
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
] | |
]; | |
}) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: There are no syntax errors, and you can assume that this code will properly run as is.