本文整理汇总了PHP中Illuminate\Http\Response::json方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::json方法的具体用法?PHP Response::json怎么用?PHP Response::json使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Response
的用法示例。
在下文中一共展示了Response::json方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
try {
$this->service->destroy($id);
return response('', 204);
} catch (\Exception $e) {
return Response::json(["error" => true, "message" => $e->getMessage()], 400);
}
}
示例2: update
public function update(Request $request)
{
if (!$this->isUnique($request->name)) {
return Response::json("This ingredient already exists", 400);
exit;
}
$recipe = Ingredient::find($request->id);
$ingredient->name = $request->name;
$ingredient->quantity = $request->quantity;
$ingredient->measure = $request->measure;
$ingredient->save();
echo json_encode(true);
exit;
}
示例3: getToken
public function getToken()
{
return Response::json(['token' => csrf_token()]);
}
示例4: destroy
/**
* DELETE deleting data tag softly
* @return Response (json)
*/
public function destroy($tagID)
{
$this->threads->delete($tagID);
return Response::json(['errors' => false, 'message' => trans('forum.tag-success-delete')]);
}
示例5: index
/**
*
* @return mixed
*/
public function index()
{
$data = ['data' => [['engine' => 'Trident', 'browser' => 'Internet Explorer 4.0', 'platform' => 'Win 95+', 'version' => '4', 'grade' => 'X'], ['engine' => 'Trident', 'browser' => 'Internet Explorer 5.0', 'platform' => 'Win 95+', 'version' => '5', 'grade' => 'C']]];
//return View::make('backend::index');
return Response::json($data);
}
示例6: anyCompletedtranscode
/**
* Accepts an SNS message to containing the video duration
*
* @param Request $request
*
* @return mixed Json containing the success of the SNS values being stored
*/
public function anyCompletedtranscode(Request $request)
{
$decodedRequestContent = json_decode(json_decode($request->getContent(), true)['Message'], true);
$video_duration = $decodedRequestContent['outputs'][0]['duration'];
$thumnail_count = floor($video_duration / env('THUMBS_MADE_FRAMERATE'));
$video_timecode = substr($decodedRequestContent['outputs'][0]['key'], 0, -5);
$video = App\Video::where('timecode', $video_timecode)->first();
$video->thumbnail_count = (int) $thumnail_count;
$video->duration_seconds = (int) $video_duration;
$success = $video->save();
return Response::json(['success' => $success], 200);
}
示例7: actionResponse
/**
* 响应实例
*/
public function actionResponse()
{
$data = array('name' => 'ken', 'age' => '32');
echo Response::json($data);
}
示例8: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
if (!$request->body or !$request->user_id) {
return Response::json(['error' => ['message' => 'Please Provide Both body and user_id']], 422);
}
$joke = Joke::find($id);
$joke->body = $request->body;
$joke->user_id = $request->user_id;
$joke->save();
return Response::json(['message' => 'Joke Updated Succesfully']);
}
示例9: function
use Illuminate\Http\Request;
use Illuminate\Http\Response;
Route::get('/', function () {
return view('welcome');
});
Route::post('/signup', function () {
$credentials = Input::only('email', 'password');
$password = Hash::make($credentials['password']);
$credentials['password'] = $password;
try {
$user = User::create($credentials);
} catch (Exception $e) {
return Response::json(['error' => 'User already exists.'], response::HTTP_CONFLICT);
}
$token = JWTAuth::fromUser($user);
return response()->json(compact('token'));
});
Route::post('/signin', function () {
$credentials = Input::only('email', 'password');
//dd($credentials);
// $token = JWTAuth::attempt($credentials);
if (!($token = JWTAuth::attempt($credentials))) {
return response()->json(false, response::HTTP_UNAUTHORIZED);
}
return response()->json(compact('token'));
});
Route::get('/restricted', ['before' => 'jwt-auth', function () {
$token = JWTAuth::getToken();
$user = JWTAuth::toUser($token);
return Response::json(['data' => ['email' => $user->email, 'registered_at' => $user->created_at->toDateTimeString()]]);
}]);
示例10: update
/**
* Update the specified resource in storage.
*
* @param MeetingRequest $request
* @param int $meetingId
* @param int $groupId
* @return mixed
*/
public function update(MeetingRequest $request, $groupId, $meetingId)
{
$group = Group::findOrFail($groupId);
$this->authorize($group);
$meeting = Meeting::findOrFail($meetingId);
$this->authorize($meeting);
$input = $request->all();
//the planner cannot modify the duration of a planed meeting
if ($meeting->start_time != NULL && $meeting->duration != $input['duration']) {
return Response::json(['error' => 'the meeting is already planned, you cannot change the duration'], 422);
}
$meeting->update($input);
return $meeting;
}