I need to build a personaliced response to get one URL returned from API. In my function store i´m saving all data in my db ok. I have a personaliced class that this class have any method to connect API and return response, etc. In my function store, i have this call:
我需要建立一个个性化的响应,以获得一个从API返回的URL。在我的函数存储中,我正在将所有数据保存在我的数据库中。我有一个个性化的类,这个类有任何方法来连接API和返回响应等。在我的函数库中,我有这样的调用:
return redirect()->route('commercialautograph.precontract', ['precontract' => $precontract]);
This call return response from API:
此调用返回来自API的响应:
$response = $this->client->request('POST', $url, [
'auth' => [config("viafirma.apiKey.username"), config("viafirma.apiKey.password")],
'json' => $json
]);
return $response;
if i build mehtod in my controller to get link from API, return BASE64´s pdf that i i´m sending to API. that's why i´m building redirect to other route, to close other operations. But my problem it´s that when i´m doing redirect, laravel returned me HTML:
如果我在我的控制器中构建方法以从api获得链接,则返回我要发送给api的Base64‘S pdf。这就是为什么我正在建设重定向到其他路线,以关闭其他业务。但我的问题是,S,当我做重定向时,Laravel给我返回了Html:
{data: '<!DOCTYPE html>\r\n <html lang="en">\r\n <he…\n\r\n </div>\r\n \r\n </body>\r\n</html>', status: 200, statusText: 'OK', headers: {…}, config: {…}, …}
This example it´s a webrowser console.
这个例子是S的一个网络浏览器控制台。
My route is:
我的路线是:
Route::prefix('commercial')->name('commercial')->group(function(){
Route::get('autograph/{precontract}', [CommercialPreContractController::class, 'autograph'])->name('autograph.precontract');
}
this route call other function in my same controller, that in this moment i want to arrive to function:
此路由调用我的同一控制器中的其他函数,此时我想要到达该函数:
/**
* Function to digital signature precontract
*/
public function autograph(Array $precontract)
{
echo "llego¿?";
exit();
try{
I haven´t got any problem in logs.. And i don´t know that i´m doing wrong, but i can´t arrive to my function. I can´t to do $this->autograph
beacause i need return response from API and read it in VUE js
我在原木上没有任何问题..我不知道我做错了什么,但我不能到达我的功能。我不能做$This->签名,因为我需要从API返回响应,并以VUE js格式读取它
I hope that anybody can help me.
我希望任何人都能帮助我。
Sorry for my bad english and thanks you very much for readme.
很抱歉我的英语不好,非常感谢你的自述。
route list:
路由列表:
GET|HEAD commercial/autograph/{precontract} commercialautograph.precontract › Commercial\CommercialPreContractCont…
更多回答
You question is incomprehensible. You have to describe better what you want to achieve, what you have implemented and what is your problem, otherwise it will hard for anyone to help you. Show the result of php artisan route:list
你的问题令人费解。你必须更好地描述你想要实现什么,你已经实施了什么,你的问题是什么,否则任何人都很难帮助你。显示php工匠路线的结果:列表
So I spent some time reading the post and trying to figure out the process or the logic you're using. This is my conclusion: 1) A user submits a form with a PDF file.
2) The controller encodes the PDF content in BASE64.
3) An API request is sent with the BASE64-encoded PDF, along with authentication (user/password).
4) The API authenticates the request, saves the BASE64 PDF, and processes it on the server.
5) The API responds by providing a link.
6) The controller extracts the link from the API response ($response).
所以我花了一些时间阅读这篇文章,试图弄清楚你使用的过程或逻辑。我的结论是:1)用户提交包含PDF文件的表单。2)控制器对PDF内容进行Base64编码。3)API请求与Base64编码的PDF一起发送,并附带身份验证(用户/密码)。4)API对请求进行鉴权,保存Base64 PDF,并在服务器上进行处理。5)API通过提供链接进行响应。6)控制器从API响应($Response)中提取链接。
7) A redirection to another route occurs.
8) The target route's controller method is executed, handling the link and rendering an HTML view or performing other actions as needed.
Is it accurate?
7)重定向到另一条路由。8)执行目标路线的控制器方法,处理链接并呈现一个HTML视图或根据需要执行其他操作。这是准确的吗?
@haruk1515 yes, it´s exactly
@haruk1515是的,就是S
@Theofanis i updated my question with my route defined
@Theofanis我更新了我的问题,定义了我的路线
You cannot send array of data as path parameters, it will not be mapped to any route. This will not work with any route method POST, GET, etc.
您不能将数据数组作为路径参数发送,它不会映射到任何路由。这不适用于任何路由方法POST、GET等。
Remove {precontact}
from path param, give it a static name e.g. commercial/autograph/precontact
so this will be a static route. Send to that endpoint specific query (GET) parameters e.g. id, name ?id=...&name=...
etc.
从路径参数中删除{preContact},为其指定一个静态名称,例如商业/亲笔签名/PreContact,因此这将是一条静态路由。向该端点发送特定查询(GET)参数,例如id、name?id=...&name=...等。
Also public function autograph(Array $precontract)
does not work for any kind of data. Array $precontract
is invalid for controllers in Laravel. It should be replaced with public function autograph(Request $request)
see laravel docs. From there get the params like $request->input('id')
.
此外,公共函数签名(数组$预约)对任何类型的数据都不起作用。数组$预约对于Laravel中的控制器无效。它应该被替换为公共函数签名(REQUEST$REQUEST),参见laravel文档。从那里获得参数,如$REQUEST->INPUT(‘id’)。
So after all these the redirect command will be
因此,在所有这些之后,重定向命令将是
return redirect()->route('commercialautograph.precontract', ['id' => $precontract['id'], 'name' => $precontract['name']);
更多回答
我是一名优秀的程序员,十分优秀!