jeudi 30 novembre 2017

Laravel - Weird Invalid date time format error when updating post

I am making an edit page to edit posts on my website, Each post is inside of a channel. When I try to edit the post without changing the channel it is in. It gives me a weird error stating:

Invalid DateTime format: 1366 Incorrect integer value: 'PHP' for column 'channel_id' at row 1

But however, When I edit the channel too, It works perfectly fine. What is causing this? I think it has something to do with my form. A post has a channel_id. so that connects it to a channel with that ID. The relations between the two is fine.

This the the piece of form that I think is causing the issue:

<div class="form-group row">
   <div class="col-md-12">
      <label for="Kanaal">Kanaal:</label>
   </div>
   <div class="col-md-12">
     <select class="form-control" id="Kanaal" name="channel_id">
       <option selected></option>
       @foreach($channels as $channel)
       <option value="" >
       
       </option>
       @endforeach
     </select>
   </div>
 </div>

The method where I store the updated post looks like this:

public function updatePost(Request $request, $id)
{

    $post = Post::find($id);
    $post->channel_id = $request->channel_id;
    $post->title = $request->title;
    $post->text = $request->text;
    $post->slug = str_slug($request->title);

    $post->save();

    return back()->with('flash', 'Het bericht is bewerkt!');
}

It reaches the method just fine. But when I do not edit the channel option tag it gives me that error, While if I do edit it, it works fine.

I don't know if I'm explaining this well, But this is the best I can do. Thanks in advance!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2zS9lEM
via IFTTT

Aucun commentaire:

Enregistrer un commentaire