在 PHP 8.1 中,readonly 关键字现已可用。我很好奇它的目的。它是为了帮助编辑者认识到某个属性是只读的,还是为了帮助客户理解这个特性,还是有其他目的?
随着 Laravel 5.7 的发布,Illuminate\Notifications\Notification 类开始提供一个 locale 方法来设置所需的语言。格式化通知时,应用程序将更改为此区域设置,然后在格式化完成后恢复到先前的区域设置。以下是此功能的示例:
$user->notify((new InvoicePaid($invoice))->locale('ar'));
Run Code Online (Sandbox Code Playgroud)
我只需要在 lumen(最新版本)中使用这个功能,但是当我实现那个 Like文档时说我得到了一个错误
Call to undefined method Laravel\Lumen\Application::getLocale()
这是因为在流明应用中没有getLocale或没有setLocale方法..所以有任何解决这个问题的想法。
我正在测试一个带有分页的 API 端点返回的 Laravel 资源
public function test_showing_all_plans(): void
{
$plans = Plan::where('is_active', true)
->paginate(10);
$resource = PlansResource::collection($plans);
$this->withHeaders([
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'AppKey' => 5,
])
->json('GET', '/api/customer/plans')
->assertStatus(200)
->assertExactJson([
$resource->response()->getData(true),
]);
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是返回的结果不一样,因为端点的路径不等于资源的返回。
这是从端点返回的结果:
"links": {
"first": "http://www.site.local/api/customer/plans?page=1",
"last": "http://www.site.local/api/customer/plans?page=3",
"next": "http://www.site.local/api/customer/plans?page=2",
"prev": null
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 3,
"path": "http://www.site.local/api/customer/plans",
"per_page": 10,
"to": 10,
"total": 24
}
Run Code Online (Sandbox Code Playgroud)
这是从资源“ $resource->response()->getData(true)”返回的代码
"links": {
"first": "http://www.site.local?page=1",
"last": "http://www.site.local?page=3",
"next": "http://www.site.local?page=2",
"prev": null
}, …Run Code Online (Sandbox Code Playgroud)