本文整理汇总了PHP中Illuminate\Http\Request::replace方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::replace方法的具体用法?PHP Request::replace怎么用?PHP Request::replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Request
的用法示例。
在下文中一共展示了Request::replace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: call
/**
* @param $uri
* @param $method
* @param array $parameters
* @param bool $collection
*
* @return mixed|string
*/
public function call($uri, $method, $parameters = [], $collection = true)
{
try {
$origin_input = $this->request->input();
$request = $this->request->create($uri, $method, $parameters);
$this->request->replace($request->input());
$dispatch = $this->router->dispatch($request);
$this->request->replace($origin_input);
return $this->getResponse($dispatch, $dispatch->getContent(), $collection);
} catch (NotFoundHttpException $e) {
throw new NotFoundHttpException('Request Not Found.');
}
}
示例2: saveFiles
/**
* File upload trait used in controllers to upload files
*/
public function saveFiles(Request $request)
{
/**
* Get Controller Name for uploade folder
*/
$action = app('request')->route()->getAction();
$controller = class_basename($action['controller']);
$controller = explode('@', $controller);
$folder_name = strtolower(str_replace('Controller', '/', $controller[0]));
if (!file_exists(base_path('uploads/') . $folder_name)) {
mkdir(base_path('uploads/') . $folder_name, 0777);
mkdir(base_path('uploads/thumb/') . $folder_name, 0777);
}
foreach ($request->all() as $key => $value) {
if ($request->hasFile($key)) {
if ($request->has($key . '_w') && $request->has($key . '_h')) {
// Check file width
$filename = $folder_name . time() . '-' . $request->file($key)->getClientOriginalName();
$file = $request->file($key);
$image = Image::make($file);
Image::make($file)->resize(50, 50)->save(base_path('uploads/thumb') . '/' . $filename);
$width = $image->width();
$height = $image->height();
if ($width > $request->{$key . '_w'} && $height > $request->{$key . '_h'}) {
$image->resize($request->{$key . '_w'}, $request->{$key . '_h'});
} elseif ($width > $request->{$key . '_w'}) {
$image->resize($request->{$key . '_w'}, null, function ($constraint) {
$constraint->aspectRatio();
});
} elseif ($height > $request->{$key . '_w'}) {
$image->resize(null, $request->{$key . '_h'}, function ($constraint) {
$constraint->aspectRatio();
});
}
$image->save(base_path('uploads') . '/' . $filename);
$request->replace(array_merge($request->all(), [$key => $filename]));
$request->files->remove($key);
} else {
$filename = $folder_name . time() . '-' . $request->file($key)->getClientOriginalName();
$request->file($key)->move(base_path('uploads'), $filename);
$request->replace(array_merge($request->all(), [$key => $filename]));
$request->files->remove($key);
}
// Check & Delete current file
if ($request->has($key . '_c')) {
$this->deleteFiles($request->{$key . '_c'});
}
}
}
}
示例3: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$input = $request->all();
array_set($input, 'match.id', $request->route('matchId'));
$request->replace($input);
return $next($request);
}
示例4: destroy
/**
* Unfallow a User
*
* @param $userIdToUnfallow
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy($userIdToUnfallow, Request $request)
{
$request->replace(array_add($request->all(), 'userId', Auth::id()));
$this->dispatcher->dispatchFrom(UnfallowUser::class, $request);
Flash::success('You have now unfallowed this user');
return Redirect::back();
}
示例5: replaceRequestInput
/**
* Replace the request input with the previous request input.
*
* @return void
*/
protected function replaceRequestInput()
{
array_pop($this->requestStack);
$previous = end($this->requestStack);
$this->router->setCurrentRequest($previous);
$this->request->replace($previous->input());
}
示例6: invoke
/**
* Call internal URI with parameters.
*
* @param string $uri
* @param string $method
* @param array $parameters
* @return mixed
*/
public function invoke($uri, $method, $parameters = array())
{
// Request URI.
$uri = '/' . ltrim($uri, '/');
// Parameters for GET, POST
$parameters = $parameters ? current($parameters) : array();
try {
// store the original request data and route
$originalInput = $this->request->input();
$originalRoute = $this->router->getCurrentRoute();
// create a new request to the API resource
$request = $this->request->create($uri, strtoupper($method), $parameters);
// replace the request input...
$this->request->replace($request->input());
$dispatch = $this->router->dispatch($request);
if (method_exists($dispatch, 'getOriginalContent')) {
$response = $dispatch->getOriginalContent();
} else {
$response = $dispatch->getContent();
}
// Decode json content.
if ($dispatch->headers->get('content-type') == 'application/json') {
if (function_exists('json_decode') and is_string($response)) {
$response = json_decode($response, true);
}
}
// replace the request input and route back to the original state
$this->request->replace($originalInput);
$this->router->setCurrentRoute($originalRoute);
return $response;
} catch (NotFoundHttpException $e) {
}
}
示例7: it_sets_page_numbers_in_the_title
/** @test */
public function it_sets_page_numbers_in_the_title()
{
$request = new Request();
$request->replace(['page' => '2']);
$meta = new MetaDataService($request);
$meta->setMeta('Bar');
$this->assertEquals('Bar (Page 2) - Site Name', $meta->metaTitle());
}
示例8: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, \Closure $next)
{
$input = $request->input(null, []);
array_walk_recursive($input, function (&$val) {
$val = trim($val);
});
$request->replace($input);
return $next($request);
}
示例9: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
if ('testing' === $this->app->environment() && $request->has('_token')) {
$input = $request->all();
$input['_token'] = $request->session()->token();
// we need to update _token value to make sure we get the POST / PUT tests passed.
Log::debug('Input token replaced (' . $input['_token'] . ').');
$request->replace($input);
}
return $next($request);
}
示例10: getOAuthToken
/**
* @param Request $request
* @return \OAuth2\HttpFoundationBridge\Response
*/
public function getOAuthToken(Request $request)
{
// adding the client secret into the request object
$requestArray = $request->all();
$requestArray['client_secret'] = env('APP_KEY');
$request->replace($requestArray);
$bridgedRequest = \OAuth2\HttpFoundationBridge\Request::createFromRequest($request->instance());
$bridgedResponse = new \OAuth2\HttpFoundationBridge\Response();
$bridgedResponse = \App::make('oauth2')->handleTokenRequest($bridgedRequest, $bridgedResponse);
return $bridgedResponse;
}
示例11: saveFiles
/**
* File upload trait used in controllers to upload files
*/
public function saveFiles(Request $request)
{
foreach ($request->all() as $key => $value) {
if ($request->hasFile($key)) {
$filename = time() . '-' . $request->file($key)->getClientOriginalName();
$request->file($key)->move(public_path('uploads'), $filename);
$request->replace(array_merge($request->all(), [$key => $filename]));
$request->files->remove($key);
}
}
}
示例12: login
protected function login(Request $request)
{
// we flash the request
$request->flash();
// we sanitize the entries
$request->replace(InputSanitizer::sanitize($request->all()));
// we set the remember to false if we do not find it
$request->merge(['remember' => $request->get('remember', false)]);
// we check the inputs validity
$rules = ['email' => 'required|email', 'password' => 'required', 'remember' => 'required|boolean'];
if (!Validation::check($request->all(), $rules)) {
return redirect()->back();
}
// we try to authenticate the user
try {
if (!($user = Sentinel::authenticate($request->except('remember'), $request->get('remember')))) {
Modal::alert([trans('auth.message.login.failure')], 'error');
return redirect()->back();
}
// we notify the current user
Modal::alert([trans('auth.message.login.success', ['name' => $user->first_name . " " . $user->last_name])], 'success');
// redirect to the url stored in the session
if ($url = session()->get('previous_url')) {
session()->forget('previous_url');
return redirect($url);
} else {
// or redirect to home
return redirect(route('home'));
}
} catch (NotActivatedException $e) {
// we log the error
CustomLog::error($e);
// we notify the current user
Modal::alert([trans('auth.message.activation.failure'), trans('auth.message.activation.email.resend', ['email' => $request->get('email'), 'url' => route('account.activation_email', ['email' => $request->get('email')])])], 'error');
return redirect()->back();
} catch (ThrottlingException $e) {
switch ($e->getType()) {
case 'ip':
// we notify the current user
Modal::alert([trans('auth.message.throttle.ip', ['seconds' => $e->getDelay()])], 'error');
break;
default:
// we notify the current user
Modal::alert([$e->getMessage()], 'error');
break;
}
return redirect()->back();
} catch (Exception $e) {
// we notify the current user
\Modal::alert([trans('auth.message.login.error'), trans('global.message.global.failure.contact.support', ['email' => config('settings.support_email')])], 'error');
return redirect()->back();
}
}
示例13: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// if he has a get parameter d
if ($request->has('d')) {
$d = Demultiplexer::getByToken($request->input('d'));
// if demultiplexer with this token exists it replace parameter d by all parameter for the request
if ($d->params) {
$request->replace(json_decode($d->params, true));
}
}
return $next($request);
}
示例14: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*
* @throws \Illuminate\Session\TokenMismatchException
*/
public function handle($request, Closure $next)
{
if ('testing' === App::environment() && $request->exists('_token')) {
$input = $request->all();
$input['_token'] = $request->session()->token();
$request->replace($input);
}
if ($this->isReading($request) || $this->shouldPassThrough($request) || $this->tokensMatch($request)) {
return $this->addCookieToResponse($request, $next($request));
}
throw new TokenMismatchException();
}
示例15: postShortcut
public function postShortcut(Request $request)
{
$request->replace($this->checkShortcut($request));
if (Shortcuts::where('user_id', $request->input('user_id'))->where('name', $request->input('name'))->first()) {
return json(error(2001));
}
if (Shortcuts::create($request->all())) {
return json(['name' => $request->input('name')]);
} else {
return json(error(2000));
}
}