0

I have a problem with soft deleting posts in blog application. I don't know why after soft deleting, records with not null deleted_at columns are still visible after retrievinig. I don't know what's wrong. For example I'm seeing on the list record like :

"id" => 7
"topic" => "Całka Riemann"
"content" => "Ważne pojęcie w analizie matematycznej"
"category_id" => 3
"user_id" => 16
"created_at" => "2017-04-16 17:38:15"
"updated_at" => "2017-04-23 21:49:41"
"deleted_at" => "2017-04-23 21:49:41"

My post Model looks:

<?php

namespace artSite;

use Illuminate\Database\Eloquent\Model;
use artSite\category;
use Illuminate\Database\Eloquent\SoftDeletes;
class post extends Model
{
    use SoftDeletes;
    protected $table = 'posts';

    protected $fillable = ['topic', 'content', 'category_id','user_id'];
    protected $dates = ['deleted_at'];
    public function __construct() {


    }
    public function category(){

        return $this->belongsTo('artSite\category');

    }
    public function user(){

        return $this->belongsTo('artSite\user');
    }

}

My Route:

Route::get('dashboard/delete/{id}','adminPanelController@deletePost');

My controller's method:

public function deletePost($id){

        post::findOrFail($id)->delete();
        return redirect()->back()->withSuccess('Post has been deleted corectly.');

    }

Could someone help me with my problem? I would be very grateful, greetings.

Krzysztof Michalski
  • 791
  • 1
  • 9
  • 25
  • what laravel version is this? BTW: it is `Całka Riemanna`, not `Całka Riemann`. – Marcin Orlowski Apr 23 '17 at 22:52
  • Ive found some similar questions that could be helpful for your question. http://stackoverflow.com/questions/22426165/laravel-soft-delete-posts and http://stackoverflow.com/questions/18041155/why-soft-deleted-entities-appear-in-query-results – Jason Joslin Apr 23 '17 at 22:54
  • Can you show us how you're retrieving the post afterwards? – Brad Apr 23 '17 at 23:05

1 Answers1

0

Ok, I know what was wrong. The problem was with counstructor in post model. After deleting one that works fine.

Krzysztof Michalski
  • 791
  • 1
  • 9
  • 25