简体   繁体   English

如何将 laravel 中的请求 object 从一个文件传递到另一个文件?

[英]How to pass request object in laravel from one file to another file?

I have 3 files called RequestCriteria,GetAllDataTask,GetAllDataAction .我有 3 个名为RequestCriteria,GetAllDataTask,GetAllDataAction文件。

RequestCriteria.php

public function __construct(Request $request)
    {
        
        $this->request = $request;
    }

GetAllDataTask.php

public function run( $data)
    {
$this->repository->pushCriteria(new RequestCriteria($data));
}

GetAllDataAction.php

public function run(Request $request){
   $data=$request->all();
$result=Apiato::call("Books@GetAllDataTask",[$data]);
}

when i am passing $data in GetAllDataTask.php while calling the RequestCriteria it's throwing an error called The $data must be an Request object \\Illuminate\Http\\Request ,How to fix this issue please help me当我在调用 RequestCriteria 时在 GetAllDataTask.php 中传递 $data 时,它会抛出一个名为The $data must be an Request object \\Illuminate\Http\\Request的错误,如何解决此问题,请帮助我

In Action file it's already $request is an Request class object so you have to update in RequestCriteria.php .在 Action 文件中,它的$request已经是 Request class object 所以你必须在RequestCriteria.php中更新。

public function __construct($newObj)
    {
        
        $this->request = $newObj;
    }

i hope this will work...我希望这会奏效......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM