L
L
Li2016-05-29 14:03:10
Laravel
Li, 2016-05-29 14:03:10

Get list of db field values ​​by array in Laravel 5.2?

Good afternoon. The site displays a list of values, each has a checkbox. I got the organization id and I'm trying to list the category in the edit method. Naturally, I need to set checked to the categories that are active. Categories are rendered like this:

@foreach($places_categories as $place_category)
    <div class="checkbox">
         <input {{ in_array($place_category->id, [1,2,3,4]) ? 'checked' : '' }} type="checkbox" ... >
    </div>
@endforeach

To clarify:
$places_categories is PlaceCategory::all(); i.e. a complete list of categories.
And I get the list of organization categories like this:
$place = Place::find($id);
$my_places = $place->with('categories')->get();

I decided to do it with
{{ in_array($place_category->id, [1,2,3,4]) ? 'checked' : '' }}
, however, it is not possible to get the list of values ​​as an array. Is there any regulated way to solve the problem, please tell me, or some other method. If there are questions you don't understand, ask. I will be very grateful for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
miki131, 2016-05-29
@cubaPro

$place->categories->pluck('id');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question