如何在laravel 5.2中访问控制器中的url段

时间:2016-06-08 07:08:35

标签: php laravel-5.2

我在Laravel 5.2中工作,我想访问控制器中的URL段。我正在使用

\b([a-oq-z]+|[a-oq-z]*(p[a-gi-z][a-oq-z]*)+)p?\b

但没有打印。如何从控制器中的url获取值。

2 个答案:

答案 0 :(得分:8)

在laravel 5.2中你可以这样做..

echo request()->segment(2);

request()是Laravel 5.2中提供的几个辅助函数之一。它返回当前请求对象,因此您不需要在类顶部使用外观的使用语句。

答案 1 :(得分:0)

在Laravel 7中,我正在使用它来获取细分

from pyspark.sql import Window, WindowSpec
import pyspark.sql.functions as F
import pandas as pd

# Create the test data Assuming everyday, we have data for all departments
date = ['2020-07-06', '2020-07-06', '2020-07-06', '2020-07-06','2020-07-07','2020-07-07','2020-07-07','2020-07-07', '2020-07-08', '2020-07-08','2020-07-08','2020-07-08' ]
dept = ['Marketing', 'Sales', 'Engg', 'Sites','Marketing', 'Sales', 'Engg', 'Sites','Marketing', 'Sales', 'Engg', 'Sites',]
rate = [20,15,40,18,20, 3, 6, 9, 100,5,10,7]
df = pd.DataFrame([date, dept, rate]).T
df.columns = ['date', 'dept', 'rate']

# create spark DtaFrame
sdf = spark.createDataFrame(df)

sdf.show()

+----------+---------+----+
|      date|     dept|rate|
+----------+---------+----+
|2020-07-06|Marketing|  20|
|2020-07-06|    Sales|  15|
|2020-07-06|     Engg|  40|
|2020-07-06|    Sites|  18|
|2020-07-07|Marketing|  20|
|2020-07-07|    Sales|   3|
|2020-07-07|     Engg|   6|
|2020-07-07|    Sites|   9|
|2020-07-08|Marketing| 100|
|2020-07-08|    Sales|   5|
|2020-07-08|     Engg|  10|
|2020-07-08|    Sites|   7|
+----------+---------+----+

# Lag returns by one day
windowSpec = Window.partitionBy('dept').orderBy('date')
value_column = 'rate_shift'
value_ff = F.lag(sdf['rate'], offset=2).over(windowSpec)
sdf = sdf.withColumn(value_column, value_ff)
# returns = returns.withColumn(value_column, value_ff)

sdf.orderBy('date').show()

+----------+---------+----+----------+
|      date|     dept|rate|rate_shift|
+----------+---------+----+----------+
|2020-07-06|Marketing|  20|      null|
|2020-07-06|    Sales|  15|      null|
|2020-07-06|     Engg|  40|      null|
|2020-07-06|    Sites|  18|      null|
|2020-07-07|Marketing|  20|      null|
|2020-07-07|     Engg|   6|      null|
|2020-07-07|    Sales|   3|      null|
|2020-07-07|    Sites|   9|      null|
|2020-07-08|    Sales|   5|        15|
|2020-07-08|     Engg|  10|        40|
|2020-07-08|Marketing| 100|        20|
|2020-07-08|    Sites|   7|        18|
+----------+---------+----+----------+

rates are shiifted by 2 days