我apiResource
在 Route 中使用,它(index, create, show, update, destroy)
在exampleController
. 当我想使用 show 方法时,路由将不起作用。我该怎么办?我想是因为{fruits}
但是我没有怎么解决呢?
Route::apiResource('/fruit/{fruits}/apples', 'exampleController');
Run Code Online (Sandbox Code Playgroud)
我在浏览器中的路线是:
localhost:8000/api/fruits/testFruitSlug/apples/testAppleSlug
Run Code Online (Sandbox Code Playgroud)
apiResource 和 resource in route 的区别: Route::apiResource()
只为 index、store、show、update 和 destroy 创建路由,同时Route::resource()
还添加了在 API 上下文中没有意义的 create 和 edit 路由。
我在 Laravel 验证中使用 required if ,但它不起作用。我的错误是什么?
public function rules()
{
if (!empty($this->game_id)) {
$game = Game::find($this->game_id);
$game_type = $game->type;
} else {
$game_type = 'sport';
}
return [
'game_id' => 'required',
'platform_id' => 'required_if:' . $game_type . ',==,electronic',
]
}
Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用了很多match
查询。现在,我刚刚面临term
Elasticsearch 中的查询。如果指定了查询的关键字,则术语查询似乎会更快。现在我有一个问题..我应该重构我的代码(很多)并使用 term 而不是 match 吗?使用 term 的性能比 match 好多少?
在我的查询中使用术语:
main_query["query"]["bool"]["must"].append({"term":{object[..]:object[...]}})
Run Code Online (Sandbox Code Playgroud)
在我的查询中使用匹配查询:
main_query["query"]["bool"]["must"].append({"match":{object[..]:object[...]}})
Run Code Online (Sandbox Code Playgroud)