how to concatenate variable with database field name in laravel blade?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
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: 
laravel variables concatenation laravel-blade
add a comment |
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: 
laravel variables concatenation laravel-blade
add a comment |
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: 
laravel variables concatenation laravel-blade
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: 
laravel variables concatenation laravel-blade
laravel variables concatenation laravel-blade
edited Jan 4 at 7:43
Armali
7,8251238107
7,8251238107
asked Jan 4 at 7:35
Ali AhmadAli Ahmad
316
316
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I think the problem is in the way you call the property of the object. You want to get the name_en or name_pe from $product object.
When you do $product->name_.$lng, what actually happen is the PHP get the value of $product->name_ and then add it with the value in $lng. In this case, the $product->name_ is NULL and $lng is en or pe that why the output is either en or pe.
So, the solution is, you should change the way you call the attribute with $product['name_' . $lng] or prepare a variable $column = 'name_' . $lng; $product->$column; or you can do this $product->{'name_' . $lng}.
You can refer the operation from this post.
Sure, I'm glad it helps you!
– EdTan
Jan 4 at 10:04
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54034781%2fhow-to-concatenate-variable-with-database-field-name-in-laravel-blade%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think the problem is in the way you call the property of the object. You want to get the name_en or name_pe from $product object.
When you do $product->name_.$lng, what actually happen is the PHP get the value of $product->name_ and then add it with the value in $lng. In this case, the $product->name_ is NULL and $lng is en or pe that why the output is either en or pe.
So, the solution is, you should change the way you call the attribute with $product['name_' . $lng] or prepare a variable $column = 'name_' . $lng; $product->$column; or you can do this $product->{'name_' . $lng}.
You can refer the operation from this post.
Sure, I'm glad it helps you!
– EdTan
Jan 4 at 10:04
add a comment |
I think the problem is in the way you call the property of the object. You want to get the name_en or name_pe from $product object.
When you do $product->name_.$lng, what actually happen is the PHP get the value of $product->name_ and then add it with the value in $lng. In this case, the $product->name_ is NULL and $lng is en or pe that why the output is either en or pe.
So, the solution is, you should change the way you call the attribute with $product['name_' . $lng] or prepare a variable $column = 'name_' . $lng; $product->$column; or you can do this $product->{'name_' . $lng}.
You can refer the operation from this post.
Sure, I'm glad it helps you!
– EdTan
Jan 4 at 10:04
add a comment |
I think the problem is in the way you call the property of the object. You want to get the name_en or name_pe from $product object.
When you do $product->name_.$lng, what actually happen is the PHP get the value of $product->name_ and then add it with the value in $lng. In this case, the $product->name_ is NULL and $lng is en or pe that why the output is either en or pe.
So, the solution is, you should change the way you call the attribute with $product['name_' . $lng] or prepare a variable $column = 'name_' . $lng; $product->$column; or you can do this $product->{'name_' . $lng}.
You can refer the operation from this post.
I think the problem is in the way you call the property of the object. You want to get the name_en or name_pe from $product object.
When you do $product->name_.$lng, what actually happen is the PHP get the value of $product->name_ and then add it with the value in $lng. In this case, the $product->name_ is NULL and $lng is en or pe that why the output is either en or pe.
So, the solution is, you should change the way you call the attribute with $product['name_' . $lng] or prepare a variable $column = 'name_' . $lng; $product->$column; or you can do this $product->{'name_' . $lng}.
You can refer the operation from this post.
answered Jan 4 at 7:54
EdTanEdTan
263
263
Sure, I'm glad it helps you!
– EdTan
Jan 4 at 10:04
add a comment |
Sure, I'm glad it helps you!
– EdTan
Jan 4 at 10:04
Sure, I'm glad it helps you!
– EdTan
Jan 4 at 10:04
Sure, I'm glad it helps you!
– EdTan
Jan 4 at 10:04
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54034781%2fhow-to-concatenate-variable-with-database-field-name-in-laravel-blade%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown