In my update function the generated dropdown list of categories is always set to the first one pulled from the database.
Given a list 1,2,3. Current article has a categorie 2. And you want to update it, categorie is set to 1 in update page.
I want this to remain the current value in the database if nothing is changed. I've tried to prepend to the lists array but without succes.
This is the code:
1) Part of update function
$data['post'] = Blog::where('slug', $slug)->first();
//Getting the current article category ID
$currentCat = $data['post']->category;
//Getting the current article category name
$currentCatName = $data['post']->categoryy->name;
$data['categories'] = [$currentCatName => $currentCat] + BlogCategories::orderBy('name', 'asc')->lists('name', 'id');
return view('admin.blog.edit', $data);
2) Update view
{!! Form::open(['url' => 'admin/blogbeheer/update/'.$post->id.'', 'files' => true]) !!}
<div class="form-group">
{!! Form::label('title', 'Titel: ') !!}
{!! Form::text('title', $post->title, ['class' => 'form-control', 'maxlength' => '255']) !!}
</div>
<!-- form input -->
<div class="form-group">
{!! Form::label('Body', 'Body: ') !!}
{!! Form::textarea('body', $post->blog_text, ['class' => 'form-control', 'id' => 'body']) !!}
</div>
<div class="form-group">
{!! Form::label('category', 'Kies een categorie: ') !!}
{!! Form::select('category', $categories) !!}
</div>
<div class="form-group">
<img src="../../../{{ $post->img }}" width="400px">
</div>
<!-- form input -->
<div class="form-group">
{!! Form::label('picture', 'Afbeelding: ') !!}
{!! Form::file('picture', null, ['class' => 'form-control']) !!}
</div>
<!-- Form input -->
<div class="form-group">
{!! Form::submit('Bewaar', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}