Here is my Query
$TagDatas = TagModel::whereIn('TagId', array($BlogData->Tagged))->get();
The $BlogData->Tagged
has the value 1,2,3
(Not as array but just as a character)
Here is my Model
<?php
class TagModel extends Eloquent
{
protected $primaryKey = 'AutoID';
protected $table = 'tag';
Then i do
@foreach($TagDatas as $TagData)
{{ $TagData->TagName }}
@endforeach
It shows only the first element in the tag Table
Even when i debug it shows me
select * from `tag` where `TagId` in (1,2,3)
What is that i am missing ?
If you pass a string value to the wherein()
, it will be treated as a literal string when Eloquent prepares its bindings, so the statement that is actually executed will be
select * from `tag` where `TagId` in ('1,2,3')
You need to pass each value 1, 2 and 3 as a separate array entries so that they will be bound correctly
$TagDatas = TagModel::whereIn('TagId', explode(',', $BlogData->Tagged))
->get();
so that wherein will treat the three as individual array elements, giving an executed query of
select * from `tag` where `TagId` in (1, 2, 3)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments