laravel - Laravel queue dispatch() 函数忘记/不传递值
问题描述
我正在尝试将一些文件分派到我的队列中。dispatch() 函数不能在我的东西周围工作 - 例如:
$auth = Auth::user();
$name = $request->file('file')->getClientOriginalName();
给我一个空值,什么时候DD($...);
?!
$userid = User::find(1);
(通过点击用户 ID ..)工作正常!有人可以解释为什么 dispatch() 函数对我不起作用吗?
作业代码:`class File_Upload implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $directory;
protected $uploadDataName;
protected $inputFormName;
protected $request;
public function __construct( $directory, $uploadDataName, $inputFormName )
{
//$this->$request = $request;
$this->directory = $directory;
$this->uploadDataName = $uploadDataName;
$this->inputFormName = $inputFormName;
}
$request, $directory, $uploadDataName, $inputFormName
public function handle()
{
//vars
$request = new Request;
dd($request->file());
$name = $this->request->file($this->inputFormName)->getClientOriginalName(); // 'file' z.B
$validate = Validator::make($this->request->all(),
[
$this->inputFormName => "required|max:1000"
] );
if ( $validate->fails() )
{
return response()->json('file.prop.error'); // JSON response!
}
// get client-data Name
if ($name !== $this->uploadDataName)
{
return response()->json('file.name.error'); // JSON response!
}
$this->request->file($this->inputFormName)->storeAs($this->directory, $name) ;
//event(new Event_Data_Upload_successfull( SupportController::getAuthUser(), $uploadDataName, $directory ) );
}
控制器...
dispatch( new File_Upload('name', 'name.csv', 'file') );
return redirect('/');
在同步模式下,代码可以 100% 正常工作。
解决方案
推荐阅读
- excel - 如果单元格中的值不等于另一个值,则按索引删除一行
- kubernetes - 在 Kubernetes 中使用具有多个动态命名空间的 Vault
- xamarin.ios - 无法在 Visual Studio for Mac 中将资源文件添加到 xamarin android 项目
- css - 悬停效果在谷歌浏览器中无法正常工作
- javascript - Javascript - 将对象附加到 JSON 文件
- apache-nifi - 在多个shemas上执行单个查询-NiFi
- c - Visual Studio Community 2017 cl 链接器不会链接 GTK3 库?
- react-native - 无法生成签名的 APK 反应原生应用
- java - 一个对象,多个函数调用 - Python & Java
- rest - 如何保护 api rest symfony?