4 years ago

Paste data to select field

Posted 4 years ago by Donika

Hello, i try to add to my post category field. I have categories table and in my PostController i have this

  public function create()
        $categories = Category::lists('id', 'title')->all();
        return view('', ['categories' => $categories]);

in view this:

<select name="confirmed"class="form-control">
      <option value="0">Select</option>
      @foreach ($categories as $category)
              <option value="{ { $category['id'] } }">{ { $category['title'] } }</option>

if i write dd($categories) in the top of my file i see my array

array:2 [▼
  "News" => 1
  "Web development" => 2

but, in foreach i see only numbers without title, Where i wrong?

And i think my array a little bit strange... I want smth like this $category['id'] $category['title'] in foreach.

Please sign in or create an account to participate in this conversation.