本文整理汇总了PHP中Illuminate\Http\Request::url方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::url方法的具体用法?PHP Request::url怎么用?PHP Request::url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Request
的用法示例。
在下文中一共展示了Request::url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resolve
/**
* Resolve the post.
*
* @return PostInterface|null
*/
public function resolve()
{
$url = $this->request->url();
$tmp = explode('/', $url);
$last_seg = end($tmp);
return $this->repository->findBySlug($last_seg);
}
示例2: email
public function email(Request $request)
{
$data = [];
// @todo: place the validation logics somewhere else
if ($request->isMethod('post')) {
// Require only first row
$validator = \Validator::make($request->all(), ['invite.email.0' => 'required', 'invite.name.0' => 'required']);
// Validate the inputs
$validator->each('invite.email', ['email']);
$validator->each('invite.name', ['max:50', 'min:5']);
$validator->setCustomMessages(['invite.email.0.required' => 'First row email required', 'invite.name.0.required' => 'First row name required']);
if ($validator->fails()) {
return redirect($request->url())->withInput()->withErrors($validator->errors());
}
foreach ($request->input('invite.email') as $key => $email) {
$name = $request->input('invite.name.' . $key, strstr($email, '@', true));
// Sometimes exception is thrown even though mail is sent successfully
try {
\Mail::send('emails.invitation', compact('name', 'email'), function ($mail) use($email, $name) {
$mail->from('invitation@footies.report', 'Footies Report')->to($email, $name)->subject('Invitation to join Footies Report!');
});
} catch (\Exception $e) {
// Do nothing
}
}
return redirect($request->url())->with('success', 'Processed successfully');
}
return view('admin.invite.email', $data);
}
示例3: generateMenu
private function generateMenu()
{
$currentUrl = $this->request->url();
$user = $this->request->user();
if (empty($user)) {
return array();
}
return array(array('prefix' => 'Добрый день,', 'href' => route('admin.user.show', $this->request->user()->id), 'link' => $this->getUserName(), 'active' => $currentUrl == route('admin.user.show', $user->id) || $currentUrl == route('admin.user.edit', $user->id)), array('prefix' => '', 'href' => route('admin.user.index'), 'link' => 'Управление пользователями', 'active' => $currentUrl == route('admin.user.index')), array('prefix' => '', 'href' => route('admin.index'), 'link' => 'Рабочий стол', 'active' => $currentUrl == route('admin.index')), array('prefix' => '', 'href' => route('admin.logout'), 'link' => 'Выход'));
}
示例4: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
//check for user's role
$has_role = false;
if (!$this->auth->guest() && $this->auth->user() != null) {
$required_role = $request->route()->getAction()['role'];
if ($required_role == '*') {
$has_role = true;
} else {
$roles = $this->auth->user()->roles;
foreach ($roles as $role) {
if ($role->id_role == 'admin' || $role->id_role == $required_role) {
$has_role = true;
break;
}
}
}
}
if ($this->auth->guest() || !$has_role) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect(route('admin-login') . '?return_url=' . urlencode($request->url()));
}
}
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)
{
if (($this->isMobile() || $this->isTablet()) && !strstr($request->url(), 'sorry')) {
return redirect('sorry');
}
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 (!\App\Gini\Gapper\Client::getUserName() && !in_array($request->url(), [route('root'), route('login')])) {
return redirect()->to(route('root'));
}
return $next($request);
}
示例7: paginate
private function paginate($items, $perPage, Request $request)
{
$page = Input::get('page', 1);
// get current page or default to 1
$offset = $page * $perPage - $perPage;
return new LengthAwarePaginator(array_slice($items, $offset, $perPage, false), count($items), $perPage, $page, ['path' => $request->url(), 'query' => $request->query()]);
}
示例8: category
public function category(Request $request)
{
$lastSegment = preg_split("/\\//", $request->url());
$categorySlug = array_pop($lastSegment);
// get the last segment on the current url
$category = Tag::where('slug', $categorySlug)->first();
// check if there is no category found.
if (!$category) {
return redirect()->route('front.error-404');
}
// condition where clause for parent categories or child.
if ($category->parent_id == 0) {
$field = 'tags.parent_id';
$value = $category->id;
} else {
$field = 'tags.slug';
$value = $category->slug;
}
// Get posts by PostTag slug or parent_id field
$properties = Post::join('post_tags', 'posts.id', '=', 'post_tags.post_id')->join('tags', 'post_tags.tag_id', '=', 'tags.id')->where($field, $value)->select('posts.*', 'tags.name as tagName')->paginate(config('front.postPerPage'));
$pageTitle = 'Category: ' . $category->name;
if ($category->parent_id == 0) {
$breadcrumbData = [['url' => url(), 'name' => 'Home'], ['url' => route('front.category') . '/' . $category->slug, 'name' => $category->name]];
} else {
$breadcrumbData = [['url' => url(), 'name' => 'Home'], ['url' => route('front.category', $category->parent()->slug), 'name' => $category->parent()->name], ['url' => route('front.category') . '/' . $category->parent()->slug . '/' . $category->slug, 'name' => $category->name]];
}
return view('properties', compact('properties', 'pageTitle', 'breadcrumbData'));
}
示例9: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// Put in cache all of route which are tag
$routes = Cache::remember('tags', 120, function () {
return Route::all();
});
$results = [];
// Check if current route has tags
foreach ($routes as $route) {
if (preg_match('%^' . $route->route . '$%', $request->url())) {
array_push($results, $route->tag_container_id);
}
}
// Get all container tag of the current route and add this to the layout
$contents = Tag::whereIn('tag_container_id', $results)->get();
if ($contents) {
foreach ($contents as $content) {
// if data content format this to integrate them into the script
if ($content->data) {
$data = explode(',', $content->data);
$params = [];
foreach ($data as $value) {
$params[] = "'+ {$value} +'";
}
$script = sprintf($content->content, ...$params);
} else {
$script = $content->content;
}
// add script to namespace declared in database
js($content->position . '-tag')->append($script);
}
}
return $next($request);
}
示例10: __construct
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(Request $r)
{
date_default_timezone_set("Asia/Jakarta");
//$this->middleware('auth');
//echo "<pre>".print_r($_SERVER,1)."</pre>";
$log = new Logdata();
$log->idpengguna = Auth::check() ? Auth::user()->id : 0;
$log->url = $r->url();
$log->user_agent = $_SERVER['HTTP_USER_AGENT'];
$log->ip = $_SERVER['REMOTE_ADDR'];
$log->ip_port = isset($_SERVER['REMOTE_PORT']) ? $_SERVER['REMOTE_PORT'] : "";
$log->http_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : "";
$log->http_referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "";
$log->pathinfo = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : "";
$log->save();
// echo Auth::user()->password;
// if(Auth::check()){
// if(Auth::user()->password==""){
// header("location:".url('notfound'));
// die();
// }
// }
// Session::put("a-".getenv('REMOTE_ADDR')."-3",'x');
foreach (\App\Popups::all() as $key) {
$isi = array();
if ($key->tipe_valid == "by_datetime" or $key->tipe_valid == "by_date") {
$cek = $this->check_in_range(date_format(date_create($key->date_valid_start . " " . $key->time_valid_start), "Y-m-d H:i:s"), date_format(date_create($key->date_valid_end . " " . $key->time_valid_end), "Y-m-d H:i:s"), date("Y-m-d H:i:s"));
if ($cek) {
if (!Session::has("a-" . getenv('REMOTE_ADDR') . "-" . $key->id)) {
Session::put("a-" . getenv('REMOTE_ADDR') . "-" . $key->id, 'x');
}
}
}
}
}
示例11: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
//
echo $request->path(), '<br>';
echo $request->url();
//return "this is Admin";
}
示例12: create
/**
* post的方式添加一条记录
*
* @return \Illuminate\Http\Response
*/
public function create(Request $request)
{
$request_url = str_replace("http://" . Config::get('app.url'), "", $request->url());
//验证参数
$validator = Validator::make($request->all(), ['name' => 'required|max:255']);
//验证参数完整性
if ($validator->fails()) {
$error = $validator->errors()->all();
//写入日志
Log::error(['error' => $error, 'request' => $request->all(), 'header' => $request->headers, 'client_ip' => $request->getClientIp()]);
//返回错误信息
return Error::returnError($request_url, 1001);
}
//验证token
// $user_id=Common::validateToken($request->get('token'));
//
// if($user_id == false){
// return Error::returnError($request_url,2002);
// }
$name = $request->get('name');
//写入操作
$add = Task::addTask($name);
$info = Task::getTaskInfo($add);
//返回对应的结果
$json_arr = ['request' => $request_url, 'ret' => $info];
return Common::returnResult($json_arr);
}
示例13: VisitorModel
function __construct(Request $request)
{
$visitorModel = new VisitorModel();
$visitorModel->ip = $request->getClientIp();
$visitorModel->url = $request->url();
$visitorModel->save();
}
示例14: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if (strpos($request->url(), '/api/') === false) {
return parent::render($request, $e);
}
$response = [];
// If the app is in debug mode
if (config('app.debug')) {
// Add the exception class name, message and stack trace to response
$response['exception'] = get_class($e);
// Reflection might be better here
$response['message'] = $e->getMessage();
$response['file'] = $e->getFile();
$response['line'] = $e->getLine();
}
// Default response of 400
$status = 400;
// If this exception is an instance of HttpException
if ($this->isHttpException($e)) {
// Grab the HTTP status code from the Exception
$status = $e->getStatusCode();
$response['status'] = $status;
$response['message'] = self::$statusMessages[$status];
}
// Return a JSON response with the response array and status code
return response()->json($response, $status)->header('Access-Control-Allow-Origin', env('ALLOWED_HOSTS', '*'))->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')->header('Access-Control-Allow-Credentials', 'true')->header('Access-Control-Allow-Headers', 'Content-Type, X-Auth-Token, Origin, Authorization');
}
示例15: login
/**
* 用户通过邮箱和密码进行登录操作
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function login(Request $request)
{
//获取当前访问的全部的地址
$request_url = str_replace("http://" . Config::get('app.url'), "", $request->url());
//验证参数
$validator = Validator::make($request->all(), ['email' => 'required|email', 'password' => 'required']);
//验证参数完整性
if ($validator->fails()) {
// var_dump($validator);
$error = $validator->errors()->all();
//写入日志
Log::error(['error' => $error, 'request' => $request->all(), 'header' => $request->headers, 'client_ip' => $request->getClientIp()]);
//返回错误信息
return Error::returnError($request_url, 1001);
}
$email = $request->get('email');
$password = $request->get('password');
//检查有没有
$user_model = User::checkUserLogin($email, $password);
if ($user_model == false) {
return Error::returnError($request_url, 2001);
}
//更新token
$token = User::updateToken($user_model);
//返回对应的结果
$json_arr = ['request' => $request_url, 'ret' => User::getUserInfo($user_model->id), 'token' => $token];
return Common::returnResult($json_arr);
}