我想在API中应用语言环境,但是它仅返回ar
语言。我想从网址[ar或en]中获取语言环境,例如:localhost/mertaah/api/en/settings
必须采用en
语言环境,但始终需要ar
<?php
namespace App\Http\Middleware;
use Closure;
class ApplyAPILocale
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
app()->setLocale($request->header('locale') ?? 'ar');
return $next($request);
}
}
答案 0 :(得分:-1)
这是可以帮助我解决问题的解决方案 https://laracasts.com/discuss/channels/laravel/pass-locale-to-url