本文整理汇总了PHP中App\Http\Controllers\Controller::response方法的典型用法代码示例。如果您正苦于以下问题:PHP Controller::response方法的具体用法?PHP Controller::response怎么用?PHP Controller::response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Http\Controllers\Controller
的用法示例。
在下文中一共展示了Controller::response方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getList
/**
* Ritorna la lista degli abbracci effettuati dall'utente.
* Gestisce anche la paginazione automaticamente.
*
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function getList(Request $request)
{
$user = $this->getAuthenticatedUser();
$hugs = Hug::where(function ($query) use($request) {
/**
* @var Builder $query
*/
$query->whereNull('closed_at')->orWhere(function ($query) {
/**
* @var Builder $query
*/
$query->whereNotNull('closed_at')->where('closed_at', '>=', Carbon::now()->subHours(24)->toDateTimeString());
// Abbracci conclusi
});
})->where(function ($query) use($user) {
/**
* @var Builder $query
*/
$query->where('user_seeker_id', '=', $user->id)->orWhere('user_sought_id', '=', $user->id);
})->paginate(20);
$response = json_decode($hugs->toJson());
$response->list = $response->data;
unset($response->data);
return parent::response($response);
}
示例2: update
public function update()
{
$user = $this->getAuthenticatedUser();
/**
* @var User $user
*/
return parent::response(["user" => $user]);
}
示例3: get
public function get($id)
{
try {
$user = User::findOrFail($id);
} catch (\Exception $e) {
return parent::response(['success' => false, 'error' => "User not found"]);
}
return $user;
}
示例4: store
/**
* @param Request $request
* @return mixed
*/
public function store(Request $request)
{
$isUser = $this->isValid($request);
if ($isUser === false) {
return Controller::response(Controller::error(22), 401);
}
$request->session()->push('user', $isUser);
return Controller::response($isUser, 200);
}
示例5: getMonthVipList
public function getMonthVipList(Request $request)
{
try {
$this->validate($request, ['month' => 'required|integer|between:1,12', 'year' => 'required|integer|between:2016,3000']);
} catch (ValidationException $e) {
$errors = $e->getErrors();
return parent::response(['validation' => false, 'errors' => $errors]);
}
//todo: da continuare
$vipList = \DB::table('user_hug_feedbacks')->select('user_id', 'users.username', \DB::raw('sum(result) as feedback_result'))->join('hugs', 'user_hug_feedbacks.hug_id', '=', 'hugs.id')->join('users', 'users.id', '=', 'hugs.user_seeker_id')->whereMonth('hugs.created_at', "=", $request->get('month'))->whereYear('hugs.created_at', "=", $request->get('year'))->groupBy('user_id')->orderBy('feedback_result', 'desc')->limit(10)->get();
return parent::response(["vipList" => $vipList]);
}
示例6: store
/**
* @param Request $request
* @return mixed
*/
public function store(Request $request)
{
$validate = ['email' => 'required|email', 'password' => 'required'];
$validator = Controller::validator($request, $validate);
if ($validator !== true) {
return Controller::response(Controller::error(38), 400);
}
$isValid = $this->isValid($request);
if ($isValid !== true) {
return Controller::response(Controller::error(21), 400);
}
if ($request->hasFile('upload')) {
$file = $request->file('upload');
$name = uniqid(rand(), true) . "." . $file->getClientOriginalExtension();
$file->move('storage/', $name);
$request['picture'] = url('/storage') . "/" . $name;
}
$response = $this->user->pushUser($request);
return Controller::response($response, 200);
}
示例7: authenticate
public function authenticate(Request $request)
{
$credentials = $request->only('email', 'password', 'fid');
$token = null;
try {
if (!($token = JWTAuth::attempt($credentials))) {
return Controller::response(Controller::error(13), 401);
}
if (!empty($request->input('fid'))) {
$user = $this->user->authFacebook($request);
}
if (!empty($request->input('email'))) {
$user = $this->user->authEmail($request);
}
$hash = compact('token');
$user['token'] = $hash['token'];
return Controller::response($user, 200);
} catch (JWTException $e) {
return Controller::response(Controller::error(14), 500);
}
}
示例8: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$user = JWTAuth::parseToken()->authenticate();
if (!JWTAuth::parseToken()->authenticate()) {
return Controller::response(Controller::error(13), 401);
}
if ($user->id != $id && !Controller::supreme($user->role)) {
return Controller::response(Controller::error(13), 401);
}
$user = json_decode($this->user->pullUser($id));
if (!empty($user) || !collect($user)->isEmpty()) {
if ($user[0]->picture) {
$picture = str_replace(url('/storage') . "/", "", $user[0]->picture);
$target = public_path('storage/') . $picture;
@chmod($target, 0777 & ~umask());
File::delete($target);
}
}
$response = $this->user->deletePicture($id);
return Controller::response($response, 204);
}
示例9: sendSelfies
/**
* Permette di caricare fino ad un massimo di 3 file
*
* @param Request $request
* @param $id
*
* @return \Illuminate\Http\JsonResponse
*/
public function sendSelfies(Request $request, $id)
{
// TODO: Da terminare
$user = $this->getAuthenticatedUser();
/**
* @var Hug $hug
*/
$hug = Hug::whereId($id)->whereNull('closed_at')->where(function ($query) use($user) {
/**
* @var Builder $query
*/
$query->where('user_seeker_id', '=', $user->id)->orWhere('user_sought_id', '=', $user->id);
})->firstOrFail();
$selfie = new UserHugSelfie();
$selfie->file_name = 'test.jpg';
$selfie->hug_id = $hug->id;
$selfie->user_id = $user->id;
$selfie->file_path = 'test/test2/test.jpg';
$selfie->file_size = 99121;
$selfie->save();
return parent::response([]);
}
示例10: userResponse
/**
* Gestisce le risposte degli utenti in seguito ad una richista di abbraccio.
*
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function userResponse(Request $request)
{
$responseType = last(explode('.', $request->route()->getName()));
if (!in_array($responseType, ['accept', 'reject', 'noResponse'])) {
// Risposta invalida
abort(404, 'Invalid response');
}
try {
$this->validate($request, ['id' => 'required|numeric|exists:searches,id']);
} catch (ValidationException $e) {
$errors = $e->getErrors();
return parent::response([], $errors);
}
$user = $this->getAuthenticatedUser();
/**
* @var Search $search
*/
$search = Search::whereId($request->input('id'))->whereNull('finished_at')->first();
if ($user->id != $search->getLastFetchedUserId()) {
// Non può rispondere a questa ricerca
// TODO: Forse bisognerebbe prevedere qualcosa, soprattuto nell'accept. (oppure gestirlo nell'app?)
abort(403);
}
switch ($responseType) {
case 'accept':
$this->userResponseAccept($search, $user);
// Termino la ricerca
$this->finish($search, self::FINISH_STATUS_SUCCESSFUL);
// salvo alcuni dati utili
$search->setFoundUserId($user->id);
$search->save();
// Notifico l'utente che ha avviato la ricerca
$this->notifyTheSearcher($search);
break;
case 'reject':
$this->userResponseReject($search, $user);
// Continuo la ricerca
$this->process($search);
break;
case 'noResponse':
$this->userResponseNoResponse($search, $user);
// Continuo la ricerca
$this->process($search);
break;
default:
}
return parent::response([]);
}
示例11: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$user = JWTAuth::parseToken()->authenticate();
if (!Controller::supreme($user->role)) {
return Controller::response(Controller::error(13), 401);
}
$response = $this->newsletter->deleteNewsletter($id);
return Controller::response($response, 204);
}
示例12: processLogin
protected function processLogin(User $user, $token)
{
if (!empty($user->activation_code)) {
return parent::response(['success' => false, 'error' => 'Your account is not active']);
}
if ($user->blocked) {
return parent::response(['success' => false, 'error' => 'Your account is blocked']);
}
$user->last_login = Carbon::now();
$user->save();
return parent::response(['token' => $token]);
}