<?php
foreach($users as $user) {
$user = User::create(array(
'user_id' => $user['user_id'],
'user_text' => "1",
'other_id' => $user['other_id']
));
}
return Response::json(['success' => true, 'message' => 'successfully', 'data' => $user], 201);
我如何发送多个创建的用户到响应中,这不允许我将用户设置为数据键,即使我试图在循环中设置返回响应(它仅允许设置值),也请进行指导。
答案 0 :(得分:1)
foreach( $users as $user ) {
$send_user[] = User::create(array('user_id' => $user['user_id'], 'user_text' => "1", 'other_id' => $user['other_id']));
}
return Response::json([
'success' => true,
'message' => 'successfully',
'data' => $send_user
], 200);
答案 1 :(得分:1)
return response()-> json(['type'=>'success','data'=> $ user],200);