lundi 4 avril 2016

How to get specific value/name using dimsav/laravel-translatable package

I have followed the doc. I created two tables (1. countries and 2. country_translations).

enter image description here

Now I changed the column name => key and value cause I can get the value (lang text) by query "key".

Say for example :

$r = 'DE';//App::getLocale(); // 'fr'
$germany = Country::where('code', $r)->first();

// I want to get value where key= 'contacts-last-name'
$translation = $germany->translate($r, true)->where('key', 'contacts-last-name')->value;

print_r($translation);
exit("----");

ERROR: Undefined property

How may I get specific value using new query/sub query (key).


For an Example here is my method and view

Updated the method as below ::

$translation = $germany->translate($r, true)->where('key', 'contacts-last-name')->first();

    print_r($translation);

and got the answer:

( [table:protected] => country_translations [timestamps] => [fillable:protected] => Array ( [0] => country_id [1] => key [2] => value [3] => locale ) [connection:protected] => [primaryKey:protected] => id [perPage:protected] => 15 [incrementing] => 1 [attributes:protected] => Array ( [id] => 1 [country_id] => 83 [key] => contacts-last-name [value] => Achternaam [locale] => DE )

In view Page I have a form :

        <label class="col-sm-2 control-label">{{trans('labels.contacts-first-name')}}</label>
        <div class="col-sm-4">
            <input name="first_name" id="first_name" type="text" class="form-control" required disabled>
        </div>

       <label class="col-sm-2 control-label">{{trans('labels.contacts-last-name')}}</label>
        <div class="col-sm-4">
            <input type="text" id="last_name" name="last_name" class="form-control" disabled>
        </div>

for this one I have a question how may I pass translate data and make transable views all the time {{trans('labels.contacts-last-name')}}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire