Laravel项目已实现本地化并且运行良好。由于用户可以进行自定义,因此可以将语言(语言环境)保存在DB中,因此出现了问题。
传递给App \ Http \ Controllers \ CustomizeController :: edit()的参数1必须是App \ Model \ Customize的实例,给出的字符串
在CustomizeController.php中
RawMaterialButton(
onPressed: ()
{
},
shape: CircleBorder( ),
fillColor: Colors.white,
)
route:list命令O / P如下:
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);
}
甚至尝试从刀片硬编码为:
GET|HEAD | {locale}/customize/{customize}/edit | customize.edit | App\Http\Controllers\CustomizeController@edit | web,setlocale,auth
完成项目available here
答案 0 :(得分:1)
错误非常直接。
通过路由参数调用edit
方法,该参数后跟您定义要从容器中获取的对象。
自从您将customize
参数传递给路由以来,您的方法参数应按如下所示进行定义:
public function edit(string $customize, App\Model\Customize $customizeModel)
{
$customizeModel
->whereUserId(Auth::user()->id)
->update(['customize' => $customize]);
$return response(); // whatever you need
}