如何在 laravel 中修改请求值?
2022-08-30 19:49:56
我有以下代码,
我的问题是如何修改请求值?
public function store(CategoryRequest $request)
{
try {
$request['slug'] = str_slug($request['name'], '_');
if ($request->file('image')->isValid()) {
$file = $request->file('image');
$destinationPath = public_path('images/category_images');
$fileName = str_random('16') . '.' . $file->getClientOriginalExtension();
$request->image = $fileName;
echo $request['image'];
$file->move($destinationPath, $fileName);
Category::create($request->all());
return redirect('category');
}
} catch (FileException $exception) {
throw $exception;
}
}
但
在每个请求上输出
echo $request['image'];
输出一些文本,如 /tmp/phpDPTIn