0

I am trying to update a model in Laravel and I have missed the following error

SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2020-03-08 02:46:51' for column deportetotal.news.updated_at at row 1 (SQL: update news set views = 1, news.updated_at = 2020-03-08 02:46:51 where id = 86)

My class model look like that

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Jenssegers\Date\Date;

class News extends Model
{

      protected $guarded=[];


      public function getImage(){

            return $this->hasOne('App\Image', 'id', 'image' );
      }

      public function tags(){
            return $this->belongsToMany('App\Tag', 'news_tags', 'news_id', 'tags_id');
      }

      public function category()
      {
            return $this->belongsTo('App\Category', 'category_id');
      }

      public function author()
      {
            return $this->belongsTo('App\User', 'user_id');
      }

      public function comments(){
            return $this->hasMany('App\Comment', 'news_id');
      }

      public function getImagePathAttribute(){
        return Storage::disk('public')->url($this->image);
      }

      public function getPublishDateAttribute(){
          return new Date($this->pubDate);
      }

}

And the fucntion controller

public function show($slug){

        $news=News::where('slug',$slug)->first();
        $news->views++;
        $news->save();

        return view('web.news.show', compact('news'));
    }

0 Answers0