V
V
vvmgev2015-08-12 11:46:27
MySQL
vvmgev, 2015-08-12 11:46:27

How to convert object on fetch?

$model = DB::table('arajin_models')->where('price','=',100)->get();
        echo $model->title;

c1455c27cf66463b8d9dce11e11793b3.PNG
and so it worksecho $model[0]->title;

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evgeny Perin, 2015-08-12
@vvmgev

try replacing ->get() with ->first()

P
Pavel Zhukau, 2015-08-12
@NikesDark

And you try to display the entire $model collection and you will immediately understand what's going on.
After all, there may be several rows in the table, where price = 100, this is the point, where returns an "array of arrays" in contrast to the find method (where id is unique).

S
Sergey Melnikov, 2015-08-12
@mlnkv

$result = DB::table('arajin_models')->where('price','=',100)->get();
$model = $result[0];
echo $model->title;

# или

$model = DB::table('arajin_models')->where('price','=',100)->first();
echo $model->title;

In general, you should not ask questions, the answers to which can be found in the documentation
laravel.com/docs/4.2/queries

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question