【发布时间】:2019-10-11 01:42:52
【问题描述】:
Laravel 项目通过本地化实现并且运行良好。进行自定义,因为用户可以将语言(区域设置)保存在 DB 中,问题就来了。
- 用户能够在数据库中保存语言。
- 当用户尝试编辑语言(区域设置)时,就会出现此问题。
传递给 App\Http\Controllers\CustomizeController::edit() 的参数 1 必须是 App\Model\Customize 的实例,给定字符串
在 CustomizeController.php 中
public function index()
{
$data = array(
'title' =>'Customize',
'heading' =>'List',
'customize' => Customize::where(['user_id' => Auth::user()->id])->first(),
);
if ($data['customize'])
{
return redirect()->route('customize.edit', ['locale' => app()->getLocale(), 'customize' => $data['customize']]); // Redirect to Edit Route If Language available in DB
}
return view('Customize.index')->with($data);
}
route:list 命令O/P如下:
GET|HEAD | {locale}/customize/{customize}/edit | customize.edit | App\Http\Controllers\CustomizeController@edit | web,setlocale,auth
甚至尝试从刀片硬编码为:
<a href="{{ url(app()->getLocale().'/customize/1/edit') }}">
<button type="button" class="btn btn-warning">Edit</button>
</a>
完成项目available here
【问题讨论】:
标签: php laravel laravel-routing laravel-5.8