我的 ProductsController 文件(公共函数更新())返回 https://mysite/shop/product/product_ID 而不是返回完整路径 https://mysite/shop/product/product_ID/name。名字不见了。名称是产品名称。状态更新后需要名称才能显示产品页面。谢谢你的帮助。
公共函数更新() { $product = Products::whereId($this->request->id)->whereUserId(auth()->id())->firstOrFail();
// Currency Position
if ($this->settings->currency_position == 'right') {
$currencyPosition = 2;
} else {
$currencyPosition = null;
}
$messages = [
'description.required' => trans('validation.required', ['attribute' => __('general.description')]),
'tags.required' => trans('validation.required', ['attribute' => __('general.tags')]),
'description.min' => trans('validation.min', ['attribute' => __('general.description')]),
'price.min' => trans('general.amount_minimum'.$currencyPosition, ['symbol' => $this->settings->currency_symbol, 'code' => $this->settings->currency_code]),
'price.max' => trans('general.amount_maximum'.$currencyPosition, ['symbol' => $this->settings->currency_symbol, 'code' => $this->settings->currency_code]),
'delivery_time.required' => trans('validation.required', ['attribute' => __('general.delivery_time')]),
'quantity.required' => trans('validation.required', ['attribute' => __('general.quantity')]),
'box_contents.required' => trans('validation.required', ['attribute' => __('general.box_contents')]),
'box_contents.max' => trans('validation.max', ['attribute' => __('general.box_contents')]),
'category.required' => trans('validation.required', ['attribute' => __('general.category')]),
];
$input = $this->request->all();
$validator = Validator::make($input, [
'name' => 'required|min:5|max:100',
'tags' => 'required',
'description' => 'required|min:10',
'price' => 'required|numeric|min:'.$this->settings->min_price_product.'|max:'.$this->settings->max_price_product,
'category' => 'required',
'delivery_time' => Rule::requiredIf($product->type == 'custom'),
'quantity' => Rule::requiredIf($product->type == 'physical'),
'box_contents' => [
'max:100',
Rule::requiredIf($product->type == 'physical')
],
], $messages);
if ($validator->fails()) {
return response()->json([
'success' => false,
'errors' => $validator->getMessageBag()->toArray(),
]);
} //<-- Validator
// Validate length tags
$tagsLength = explode(',', $this->request->tags);
foreach ($tagsLength as $tag) {
if (strlen($tag) < 2) {
return response()->json([
'success' => false,
'errors' => ['error' => trans('general.error_length_tags')],
]);
}
}
$product->name = $this->request->name;
$product->price = $this->request->price;
$product->shipping_fee = $this->request->shipping_fee ?? false;
$product->country_free_shipping = $this->request->country_free_shipping ?? false;
$product->tags = $this->request->tags;
$product->description = trim(Helper::checkTextDb($this->request->description));
$product->delivery_time = $this->request->delivery_time ?? false;
$product->quantity = $this->request->quantity ?? false;
$product->box_contents = $this->request->box_contents ?? false;
$product->category = $this->request->category;
$product->status = $this->request->status ?? '0';
$product->save();
return response()->json([
'success' => true,
'url' => url('shop/product', $product->ID)
]);