Skip to content

Instantly share code, notes, and snippets.

@arshohag
Created February 2, 2020 08:26
Show Gist options
  • Save arshohag/ece4e8c7cd102d7bb2411fcecb189c6a to your computer and use it in GitHub Desktop.
Save arshohag/ece4e8c7cd102d7bb2411fcecb189c6a to your computer and use it in GitHub Desktop.
Laravel DB localization using voyager - custom response to replace patent column with translated data
/**
* Display a listing of the Relation resource.
*
* @return \Illuminate\Http\Response
*/
public function getRelations()
{
$relations = Relation::with('dbtranslations')->get();
if ($_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? 'en' != 'en') {
foreach($relations as $relation){
if(sizeof($relation->dbtranslations)>1){
$relation['name'] = $relation->dbtranslations[1]->value;
$relation['description'] = $relation->dbtranslations[0]->value;
}
}
}
return $this->sendResponse($relations->toArray(), __('messages.get_user_recipient_relations_success'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment