1

after returning $query from this:

$query = DB::table('pets')->select('id')->where('id', '=', $pet->id)->where('user_id', '=', Auth::id())->get();

for example i get this result : [{"id":"66"}] how can i get only 66 as integer? Thanks!

1
  • 2
    Use pluck feature of laravel Commented Jul 13, 2017 at 13:21

1 Answer 1

3

Instead of get() which returns the entire collection of selected data, use value('id') to get the first value of the id field. You also wouldn't need select('id') if you use this method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.