Sharp expects localized fields to be provided as a key/value array where the keys are the locale codes.
When retrieving data in find(), use setCustomTransformer to map database columns to the locale array. When saving in update(), extract the locale values from the array and use ignore() to prevent Sharp from attempting to save the raw localization array directly to the model.
function find($id): array
{
return $this->setCustomTransformer("title", function($title, $book) {
return [
"fr" => $book->title_french,
"en" => $book->title_english
];
})
->transform(
Book::findOrFail($id)
);
}
function update($id, array $data)
{
$instance = $id ? Book::findOrFail($id) : new Book;
$data["title_french"] = $data["title"]["fr"];
$data["title_english"] = $data["title"]["en"];
$this
->ignore("title")
->save($instance, $data);
return $instance->id;
}