首页 > 解决方案 > 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% 正常工作。

标签: laravelqueuedispatch

解决方案


推荐阅读