Created
February 2, 2020 08:26
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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