试图将数据保存到db中,但是它仅返回下一页而不将数据保存到db中,是否有解决此问题的解决方案,
控制器:
WITH Q1 AS(
SELECT
customDimension.value AS UserID,
# Visits from this individual
COUNT(DISTINCT CONCAT(CAST(fullVisitorId AS STRING),CAST(visitId AS STRING))) AS visits,
# Orders from this individual
COUNT(DISTINCT hits.transaction.transactionId) AS orders,
# COUNT(DISTINCT hits.transaction.transactionId)/COUNT(DISTINCT VisitId) AS frequency,
# Conversion rate of the individual
SAFE_DIVIDE(COUNT(DISTINCT hits.transaction.transactionId),
COUNT(DISTINCT CONCAT(CAST(fullVisitorId AS STRING),CAST(visitId AS STRING)))) AS conversion_rate,
# first visit date
MIN(Date) AS first_visit_date,
# last visit date
MAX(DATE) AS last_visit_date
FROM
`project.dataset.ga_sessions_20*` AS t
CROSS JOIN
UNNEST (hits) AS hits
CROSS JOIN
UNNEST(t.customdimensions) AS customDimension
CROSS JOIN
UNNEST(hits.product) AS hits_product
WHERE
parse_DATE('%y%m%d',
_table_suffix) BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 999 day)
AND DATE_SUB(CURRENT_DATE(), INTERVAL @days_ago day)
AND customDimension.index = 2
AND customDimension.value NOT LIKE "true"
AND customDimension.value NOT LIKE "false"
AND customDimension.value NOT LIKE "undefined"
AND customDimension.value IS NOT NULL
GROUP BY
UserID
),
Q2 AS(
SELECT
customDimension.value AS UserID,
IFNULL(SUM(totals.bounces),0) AS bounces,
IFNULL(SUM(totals.transactionRevenue)/1000000,0) AS revenue
FROM
`project.dataset.ga_sessions_20*` AS t
CROSS JOIN
UNNEST(t.customdimensions) AS customDimension
WHERE parse_date('%y%m%d', _table_suffix) between
DATE_sub(current_date(), interval 999 day) and
DATE_sub(current_date(), interval @days_ago day)
AND customDimension.index = 2
AND customDimension.value NOT LIKE "true"
AND customDimension.value NOT LIKE "false"
AND customDimension.value NOT LIKE "undefined"
AND customDimension.value IS NOT NULL
GROUP BY
UserID
),
Q3 AS(
SELECT customDimension.value AS UserID, MAX(Date) AS last_order
FROM `project.dataset.ga_sessions_*` AS t
CROSS JOIN UNNEST(t.customdimensions) AS customDimension
WHERE totals.transactions > 0
AND customDimension.index = 2
GROUP BY UserID
),
Q4 AS(
SELECT customDimension.value AS UserID, MIN(Date) AS first_order
FROM `project.dataset.ga_sessions_*` AS t
CROSS JOIN UNNEST(t.customdimensions) AS customDimension
WHERE totals.transactions > 0
AND customDimension.index = 2
GROUP BY UserID
)
SELECT a.UserID AS UserID,
SUM(visits) AS visits,
IFNULL(SUM(orders),0) AS orders,
IFNULL(MIN(conversion_rate),0) AS conversion_rate,
IFNULL(SUM(bounces),0) AS bounces,
IFNULL(SUM(revenue),0) AS revenue,
IFNULL(SAFE_DIVIDE(SUM(revenue),SUM(orders)),0) AS AOV,
IFNULL(SAFE_DIVIDE(SUM(revenue),SUM(visits)),0) AS rev_per_visit,
IFNULL(SAFE_DIVIDE(SUM(bounces),SUM(visits)),0) AS bounce_rat
FROM Q1 AS a
LEFT JOIN Q2 AS b
USING (UserID)
LEFT JOIN Q4 AS f
USING (UserID)
LEFT JOIN Q3 AS l
USING (UserID)
GROUP BY UserID
刀片文件:
public function create(Request $request)
{
if ($request->isMethod('post')) {
$data = $request->all();
$categories = new Categories;
$categories->name = $data['category_name'];
$categories_description = $data['description'];
$categories->save();
return view('admin.categories.index');
}
return view('admin.categories.create');
}
路线:
<form class="k-form" method="post" action="{{ url('/admin/categories/index')}}" name="" id="k_form">@csrf
<div class="row">
<label class="col-3 col-form-label">Category Name:</label>
<div class="col-9">
<input class="form-control" type="text" name="category_name" value="" required="required">
</div>
</div>
<div class="form-group row">
<label class="col-3 col-form-label">Description:</label>
<div class="col-9">
<textarea name="description" required="required"></textarea>
</div>
</div>
<div class="form-group row">
<label class="col-3 col-form-label"></label>
<div class="col-9">
<div class="k-checkbox-single">
<input type="submit" value="Add Category" style="background-color: #5867dd; color: #fff; border-radius: 5px; padding: 10px;" name="">
</div>
</form>
答案 0 :(得分:1)
您在这里弄错了
$categories_description = $data['description'];
应该是
$categories->description = $data['description'];
希望这会有所帮助:)
答案 1 :(得分:1)
存在问题
$categories = new Categories;
我认为应该是
$categories = new Category;
或
$category = new Category; //preferred
模型是单数形式,按照laravel命名约定,表是复数形式。
此外,如果要批量分配值,请在可填充数组中添加列名。喜欢
protected $fillable = ['name', 'description'];
此外,请确保您的模型位于App文件夹中,并且尚未创建任何子目录,例如“ App \ Models”或其他内容。