Laravel Eloquent Select Issue

ABD

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 ?

Mark Baker

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Laravel Eloquent Select Issue

From Dev

Laravel Eloquent performance issue

From Dev

Forgot Password issue in Laravel Eloquent

From Dev

Laravel eloquent relationship issue in javascript

From Dev

Laravel (5.3) Eloquent - Relationship issue

From Dev

Laravel/Eloquent - Query - Select with relationship

From Dev

Laravel/Eloquent - Query - Select with relationship

From Dev

SELECT * FROM (SELECT ..) in Eloquent (Laravel4)

From Dev

laravel eloquent with multiple where conditions issue

From Dev

Laravel 5.1 Join issue while using Eloquent

From Java

How to select specific columns in laravel eloquent

From Dev

Select all from table with Laravel and Eloquent

From Dev

How to Select Certain Fields in Laravel Eloquent?

From Dev

Add extra condition on laravel eloquent select

From Dev

Laravel Eloquent hasManyThrough Relationship, SELECT without

From Dev

Select the first 10 rows - Laravel Eloquent

From Dev

Difference between select() and get() in laravel eloquent

From Dev

Laravel eloquent select first row of each group by

From Dev

How to select users except roles with Laravel Eloquent

From Dev

laravel using eloquent to populate select box and blade

From Dev

Laravel Eloquent - Select MAX with other columns

From Dev

laravel 5.1 eloquent select with prefix joined table

From Dev

Basic Select with Laravel Eloquent do not work

From Dev

laravel eloquent complex select inside where statement

From Dev

Laravel form select poulated by eloquent model

From Dev

Laravel 4 Eloquent Problems Select with hasMany Relation

From Dev

Laravel Eloquent: How to select from multiple tables

From Dev

Laravel eloquent select data only specific term

From Dev

Laravel 5 - Override Get or Select from Eloquent

Related Related

  1. 1

    Laravel Eloquent Select Issue

  2. 2

    Laravel Eloquent performance issue

  3. 3

    Forgot Password issue in Laravel Eloquent

  4. 4

    Laravel eloquent relationship issue in javascript

  5. 5

    Laravel (5.3) Eloquent - Relationship issue

  6. 6

    Laravel/Eloquent - Query - Select with relationship

  7. 7

    Laravel/Eloquent - Query - Select with relationship

  8. 8

    SELECT * FROM (SELECT ..) in Eloquent (Laravel4)

  9. 9

    laravel eloquent with multiple where conditions issue

  10. 10

    Laravel 5.1 Join issue while using Eloquent

  11. 11

    How to select specific columns in laravel eloquent

  12. 12

    Select all from table with Laravel and Eloquent

  13. 13

    How to Select Certain Fields in Laravel Eloquent?

  14. 14

    Add extra condition on laravel eloquent select

  15. 15

    Laravel Eloquent hasManyThrough Relationship, SELECT without

  16. 16

    Select the first 10 rows - Laravel Eloquent

  17. 17

    Difference between select() and get() in laravel eloquent

  18. 18

    Laravel eloquent select first row of each group by

  19. 19

    How to select users except roles with Laravel Eloquent

  20. 20

    laravel using eloquent to populate select box and blade

  21. 21

    Laravel Eloquent - Select MAX with other columns

  22. 22

    laravel 5.1 eloquent select with prefix joined table

  23. 23

    Basic Select with Laravel Eloquent do not work

  24. 24

    laravel eloquent complex select inside where statement

  25. 25

    Laravel form select poulated by eloquent model

  26. 26

    Laravel 4 Eloquent Problems Select with hasMany Relation

  27. 27

    Laravel Eloquent: How to select from multiple tables

  28. 28

    Laravel eloquent select data only specific term

  29. 29

    Laravel 5 - Override Get or Select from Eloquent

HotTag

Archive