在请求中添加自定义标头值

时间:2019-11-24 15:02:39

标签: laravel

当前正在开发CRM /应用程序的所有者方模块:

  • CRM有许多用户和餐厅
  • 用户可以拥有一个或多个商店
  • 用户可以一次在网页上查看商店(遵循RESTFul设计)。然后,他们可以查看该特定商店的库存/等

这是我面临的要求/困境:

  • 尝试不将商店的浏览与会话相关联,因为我希望能够在不同选项卡上打开多个商店。
  • 就像API一样,我们可以为标头添加值,我在想做同样的事情。在标头中添加一些内容,并在进行表单发布/获取时自动将其提交,但是它隐藏在请求中(当然,除非您检查)
  • 将商店注入AppServiceProvider中
  • 尝试尽可能地隐藏store_id(不打算加密它们,只是隐藏起来)
  • 这是一个网络应用程序,不是API

所以我尝试了这个:

//feature/controller
$products = Product::where('store_id', $this->store->id)->get();

return response()
    ->view('inventory.index', [
    'products' => $products,
    'store' => $this->store
    ])
    ->header('store', $this->store->id);

//view
//stuck here - Not fond of this, because it gives away the ID when doing `GET request`
<form action="{{ route('inventories') }}" method="POST">
    @csrf
    <input type="hidden" name="store" value="{{ $store->id }}">
</form>

//die dumping (dd) the incoming `$request` shows the hidden input, but prefer to get the header with that key as well

除此之外,这是我要显示的网址:

//Backoffice/Admin:

app.com/stores/1/inventories
app.com/stores/1/orders

//Regular users on their account (but the current store is in Store A for example, and can be Store B the next Tab)
app.com/inventories
app.com/orders

我不确定这种方法是否有效,但是我愿意提出改进建议。

我正在考虑的事情:

  • 我应该改用cookie吗?但是除非用户在浏览器中更改当前餐厅,否则我需要cookie保持不变。

更新:

  • Cookie似乎是唯一的方法,但这会使事情变得混乱。想象每个标签处理cookie。 (也要避免)
  • 和URL查询参数(我想避免使用该参数)

0 个答案:

没有答案
相关问题