本文整理汇总了PHP中Illuminate\Http\Request::segments方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::segments方法的具体用法?PHP Request::segments怎么用?PHP Request::segments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Request
的用法示例。
在下文中一共展示了Request::segments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$uri_segments = $request->segments();
if (!empty($uri_segments) && in_array("api", $uri_segments)) {
return $next($request);
}
if (\Auth::guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('http://login.' . \Config::get('app.domain') . '/');
}
}
$usuario = \Auth::user();
if (!empty($usuario)) {
//Menú de administrador
if ($usuario->hasRole('administrador')) {
\Menu::make('menu_lateral', function ($menu) {
$menu->add('Inicio', 'inicio');
});
}
} else {
\Redirect::to('/error500');
}
return $next($request);
}
示例2: getShareableModel
/**
* Fetch shareable model from db based on route params.
*
* @param Request $request
* @return App\Folder | App\File
*/
private function getShareableModel(Request $request)
{
list($route, $type, $share_id, $name) = $request->segments();
$type = strtolower($type);
$className = 'App\\' . ucfirst($type);
return App::make($className)->where('share_id', $share_id)->where('name', urldecode($name))->firstOrFail();
}
示例3: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$requestID = $request->segments()[1];
if ($requestID != Auth::user()->id) {
return redirect('profile')->with('danger', 'You do not have access to update this information');
}
return $next($request);
}
示例4: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$creditcardId = $request->segments()[2];
$ccUser = CreditCard::find($creditcardId);
if ($ccUser->user_id != Auth::user()->id) {
return redirect('profile')->with('danger', 'This credit card is not associated with you.');
}
return $next($request);
}
示例5: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$addressId = $request->segments()[2];
$addrUser = Address::find($addressId);
// if ($addrUser->user_id != Auth::user()->id)
// {
// return redirect('profile')->with('danger', 'This address is not associated with you.');
// }
return $next($request);
}
示例6: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (in_array('admin', $request->segments())) {
app()->setLocale('backend/vi');
} elseif ($lang = session()->get('locale')) {
app()->setLocale($lang);
} else {
app()->setLocale(default_lang());
}
return $next($request);
}
示例7: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// Make sure current locale exists.
$locale = $request->segment(1);
if (!array_key_exists($locale, $this->app->config->get('app.locales'))) {
$segments = $request->segments();
$segments[0] = $this->app->config->get('app.fallback_locale');
return $this->redirector->to(implode('/', $segments));
}
$this->app->setLocale($locale);
return $next($request);
}
示例8: permissions
/**
* Set permissions to be used in the controller.
*
* @param Request $request
* @return void
*/
public function permissions(Request $request)
{
$this->lock->setRole(User::$userTypes);
$user = $this->jwtAuth->user();
$owner = [User::class, 'userIsOwner', $user, last($request->segments())];
$this->lock->role(User::USER_TYPE_ADMIN)->permit(['readAll', 'readOne', 'update', 'delete']);
$this->lock->role(User::USER_TYPE_GUEST)->permit(['readOne', 'update'], [$owner]);
$this->middleware('permission:readAll', ['only' => 'getAllPaginated']);
$this->middleware('permission:readOne', ['only' => 'getOne']);
$this->middleware('permission:update', ['only' => 'patchOne']);
$this->middleware('permission:delete', ['only' => 'deleteOne']);
}
示例9: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$uri_segments = $request->segments();
$subdominio = $request->root();
$subdominio = str_replace('http://', '', $subdominio);
$subdominio = explode('.', $subdominio);
$subdominio = $subdominio['0'];
if ($subdominio === "api") {
return $next($request);
}
return parent::handle($request, $next);
}
示例10: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
// Throw 404 HTTP error if not an Ajax request
if (!$request->ajax()) {
$segments = $request->segments();
$lang = array_shift($segments);
$url = url() . '/' . $lang . $request->path . '#/' . implode('/', $segments);
return redirect($url);
}
// Process request
$response = $next($request);
return $response;
}
示例11: __construct
public function __construct(Request $request)
{
$segments = $request->segments();
$locales = LaravelLocalization::getSupportedLanguagesKeys();
$non_locale_route = '';
$lang = App::getLocale();
foreach ($segments as $segment) {
if (!in_array($segment, $locales)) {
$non_locale_route .= '/' . $segment;
}
}
DEFINED('NON_LOCALE_ROUTE') or DEFINE('NON_LOCALE_ROUTE', trim($non_locale_route, '/'));
DEFINED('LANG') or DEFINE('LANG', $lang);
}
示例12: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
$uri_segments = $request->segments();
$subdominio = $request->root();
$subdominio = str_replace('http://', '', $subdominio);
$subdominio = explode('.', $subdominio);
$subdominio = $subdominio['0'];
if ($subdominio === "api") {
return \Response::json(array('success' => false, 'message' => 'No se ha podido iniciar sesión'));
}
return redirect()->guest('auth/login');
}
return $next($request);
}
示例13: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$segments = $request->segments();
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect($segments[0] . '/admin/login');
}
} else {
$client = \App\Administrator::where('user_id', $request->user()->id)->first();
if ($client == null) {
return redirect($segments[0] . '/admin/login')->withInput($request->only('email', 'remember'))->withErrors(['email' => 'You are not a registered admin']);
}
}
return $next($request);
}
示例14: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$segments = $request->segments();
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect($segments[0] . '/login');
}
} else {
$client = \App\Client::where('user_id', $request->user()->id)->first();
if ($client == null) {
return redirect($segments[0] . '/patch/' . $request->user()->id);
}
}
return $next($request);
}
示例15: __construct
public function __construct(Request $request)
{
$segments = $request->segments();
$locales = LaravelLocalization::getSupportedLanguagesKeys();
$non_locale_route = '';
$lang = App::getLocale();
foreach ($segments as $segment) {
if (!in_array($segment, $locales)) {
$non_locale_route .= '/' . $segment;
}
}
DEFINED('NON_LOCALE_ROUTE') or DEFINE('NON_LOCALE_ROUTE', trim($non_locale_route, '/'));
DEFINED('LANG') or DEFINE('LANG', $lang);
$categories[1] = ProductCategory::getByBrand(5);
$categories[2] = ProductCategory::getByBrand(6);
$categories[3] = ProductCategory::getByBrand(7);
$this->categories = $categories;
}