[英]Return data in Laravel/Lumen Controller
So I know you can pass data to a view in laravel
like so; 所以我知道您可以像这样将数据传递到
laravel
的视图;
return view('pages.index', ['year' => $year, 'b' => $cookie]);
But what if I'm not returning a view
? 但是,如果我不返回
view
怎么办? Basically I have a the below setup; 基本上我有以下设置;
route -> controller // on API server
With the request
coming from my web server
来自我的
web server
的request
I know I can pass a string
from my controller like so; 我知道我可以像这样从控制器传递
string
。
$response = "Valid";
return $response;
So I get Valid
as a response
in my Angular request
所以我在Angular
request
得到了Valid
作为response
success (function(response, status, headers, config){
if (response == "Valid") .....
})
Can I pass data and then access it there? 我可以传递数据然后在那里访问吗? In addition to "Valid" like is done here
return view('pages.index', ['year' => $year, 'b' => $cookie]);
除了在此处执行“有效”操作之外,还可以
return view('pages.index', ['year' => $year, 'b' => $cookie]);
If you return an array of scalar values, an object implementing Jsonable interface or array of such objects, Laravel will automatically serialize it and return JSON response. 如果返回标量值数组,实现Jsonable接口的对象或此类对象数组,Laravel将自动对其进行序列化并返回JSON响应。
Try the following: 请尝试以下操作:
return ['year' => $year, 'b' => $cookie];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.