I'm using from laravel localization to switch between two languages and dynamically retrieve the data according to the selected language.
the database field names are name_en, detail_en
in English Language and name_pe, detail_pe
in Persian Language, So I want to get the en and pe
from session and save into variable $lng
and then concatenate it to the database field in blade file.
@php
$lng = Session::get('local');
// will return en or pe
@endphp
@foreach ($products as $product)
<tr>
<td>
<input class="self_delall" id="self_delall" type="checkbox" name="delid[]" value="{{ $product->id }}"/>
</td>
<td>{{ ++$i }}</td>
<td>{{ $product->name_.$lng }}</td>
<td>{{ $product->detail_.$lng }}</td>
<td>
<a class="btn btn-info" href="{{ route('products.show',$product->id) }}">Show</a>
@can('product-edit')
<a class="btn btn-primary" href="{{ route('products.edit',$product->id) }}">Edit</a>
@endcan
@can('product-delete')
<a class="btn btn-danger" href="delete/{{ $product->id }}/1">Delete</a>
@endcan
</td>
</tr>
@endforeach
So it return only the value of $lng
instead of retrieve the database field value
the output is here: