所以我使用这个包laravel-tranlatable,使用他的方法填写多个翻译,但我不能使它工作,这是他的填写多个翻译的指南..
$data = [
'code' => 'gr',
'en' => ['name' => 'Greece'],
'fr' => ['name' => 'Grèce'],
];
$greece = Country::create($data);
echo $greece->translate('fr')->name; // Grèce
这就是我的所作所为,
控制器
$model = new Model([
'el'=>[
'name' => $request->input('el.name'),
'description' => $request->input('el.description')
],
'en'=>[
'name' => $request->input('en.name'),
'description' => $request->input('en.description')
],
]);
if($service->save()
return redirect()->route('blabla.edit',compact('model'));
}
刀片
{{ Form::text('en[name]', old('en[name]'),['class'=>'form-control']) }}
{{ Form::textarea('en[description]', old('en[description]'),['class'=>'form-control']) }}
{{ Form::text('el[name]',old('el[name]'),['class'=>'form-control']) }}
{{ Form::textarea('el[description]', old('el[description]'),['class'=>'form-control']) }}
答案 0 :(得分:1)
$ data = [ 'code'=> request('code'),
'tr' => ['name' => $request->get('name')['tr']],
'en' => ['name' => $request->get('name')['en']],
];
Country::create($data);