/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next, $obscuredParameter = 'id') { $hashids = new Hashids(config('obscure.salt'), config('obscure.length'), config('obscure.alphabet')); // decode form request hashs if ($request->request->has($obscuredParameter)) { $request->request->add([$obscuredParameter => $hashids->decode($request->request->get($obscuredParameter))[0]]); } // decode route hashs if ($this->route->parameter($obscuredParameter)) { $this->route->setParameter($obscuredParameter, $hashids->decode($this->route->parameter($obscuredParameter))[0]); } return $next($request); }
public function resize(Route $route) { /** * @var $media MediaModel */ $media = MediaModel::query()->find($route->parameter('id')); $path = storage_path('app/' . $media->path()); $url = $media->url($route->parameter('width'), $route->parameter('height'), $route->parameter('type')); $filename = public_path($url); is_file($filename) && unlink($filename); $width = $route->parameter('width') == '-' ? null : $route->parameter('width'); $height = $route->parameter('height') == '-' ? null : $route->parameter('height'); $img = \Image::make($path); $aspectRatio = $img->width() / $img->height(); $nwidth = $width; $nheight = $height; switch ($route->parameter('type')) { case 'c': if ($width !== null || $height !== null) { if ($width === null) { $aspect = intval($height * $aspectRatio) / $height; $nwidth = $img->width(); } else { if ($height === null) { $aspect = $width / intval($width / $aspectRatio); $nheight = $img->height(); } else { $aspect = $width / $height; } } if ($width !== null && $height !== null) { if ($aspect < $aspectRatio) { $img->resize(null, $height, function ($constraint) { $constraint->aspectRatio(); }); } else { $img->resize($width, null, function ($constraint) { $constraint->aspectRatio(); }); } } $img->crop($nwidth, $nheight); } break; case 'r': if ($width !== null || $height !== null) { $img->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); }); } break; } \File::makeDirectory(dirname($filename), 0777, true, true); $img->save($filename, 80); return \Redirect::to($url); }
/** * Check if the parameter of the current route has the correct value * * @param $param * @param $value * * @return bool */ public function checkRouteParam($param, $value) { if (!$this->route) { return false; } return $this->route->parameter($param) == $value; }
/** * @param Route $route * @param CmfDbObject $object * @param array $conditions */ protected function addParentIdsConditionsForDbObjectInjection(Route $route, CmfDbObject $object, array &$conditions) { foreach ($route->parameterNames() as $name) { if ($object->_hasField($name)) { $conditions[$name] = $route->parameter($name); } } }
public function rules(Route $route) { if ($route->getName() == 'backend.backend.users.update') { $rules = ['user.email' => 'required|unique:backend_users,email,' . $route->parameter('id'), 'user.active' => 'required', 'groups' => 'required']; } else { $rules = ['user.email' => 'required|unique:backend_users,email', 'user.active' => 'required', 'groups' => 'required', 'password' => 'required']; } return $rules; }
/** * Controller function to output the CSS. * * @param Route $route * @param Request $request * @param Response $response * * @return Response */ public function viewCss(Route $route, Request $request, Response $response) { if (!$this->isResponseObject($response)) { return $response; } $files = explode(',', $route->parameter('files', '')); if ($route->parameter('count', 0) != count($files)) { $this->app->abort(422, 'Length option incorrect'); } }
public function article(Route $route) { $article = Content::query()->with('category')->findOrFail($route->parameter('id')); return \View::make('frontend.article', ['article' => $article]); }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules(Route $route) { return ['name' => 'required|between:4,100', 'permalink' => 'required|between:4,100:unique:tags,permalink' . $route->parameter('tags')]; }