Skip to content

[5.1] Soft deleted records are getting fetched. #10115

@neowill2013

Description

@neowill2013

deleted_at column is set when I delete a record and trashed() is returning true for soft deleted record. But when I get the result it contains soft deleted records.

Controller: index() function

  public function index()
    {

        $articles = Article::latest()->get();

        return view( 'articles/view_articles' )->with( [
            'articles'    => $articles
        ] );
    }

Model:

<?php namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Article extends Model
{
    use SoftDeletes;

    protected $fillable = [ 'name', 'url', 'description', 'status'];

    public $dates = [ 'deleted_at' ];

}

Migration:

 Schema::create( 'articles', function ( Blueprint $table ) {
            $table->mediumInteger( 'id', true, true );
            $table->string( 'name', 500 );
            $table->string( 'url', 500 );
            $table->text( 'description' );
            $table->timestamps();
            $table->softDeletes();
            $table->enum( 'status', [ 'Y', 'N', 'D' ] )->default( 'N' );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions