Answer the question
In order to leave comments, you need to log in
How to output Response for each collection object?
public function view()
{
$posts = DB::table('posts')
->select('*')
->get('*');
foreach ($posts as $post) {
echo $post->id.'<br>';
return Response::json([
'posts'=>
[
'title'=>$post->title,
'datatime'=>$post->datetime,
'anons'=>$post->anons,
'text'=>$post->text,
'tags'=>explode(', ', $post->tags),
'image'=>$post->images
]
]);
}
}
Answer the question
In order to leave comments, you need to log in
public function view()
{
$posts = DB::table('posts')
->select('*')
->get('*');
return Response::json([
'posts' => array_map(function($post) {
return [
'title'=>$post->title,
'datatime'=>$post->datetime,
'anons'=>$post->anons,
'text'=>$post->text,
'tags'=>explode(', ', $post->tags),
'image'=>$post->images
];
}, $posts)
]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question