hayumi kuran
hayumi kuran

Reputation: 431

Why is Laravel eloquent returning empty

This is my model

namespace App\Models\Invitation;

use App\Models\Model;

class SendtoType extends Model
{
}

When i get data from SendtoType it return empty or null but i sure sendto_types table has datas

    $types = SendtoType::all();
    dd($types); // return empty collection

    $types = SendtoType::find(1); 
    dd($types);// null

It's happend after i run php artisan command:reset_table sendto_types command.

I cleared cache but it's not working.

Upvotes: 1

Views: 4780

Answers (3)

hayumi kuran
hayumi kuran

Reputation: 431

Thank you everyone, i found my mistake:

i set timestamp for table's deleted_at column but forgot to set not null so it also filled deleted_at column when i add data. That's why eloquent clause return empty.
So silly mistake!

Upvotes: 4

patricus
patricus

Reputation: 62228

Command command:reset_table is not a built in command, so you'd need to look at your source code to see what it does, but by the name of it, I would assume the command empties your table.

In this case, your table is empty, so your query will not return any results.

Upvotes: 0

Harun
Harun

Reputation: 1237

You can add protected $table = 'sendto_types'; inside your model class with actual table name in your database.

class SendtoType extends Model
{
   protected $table = 'sendto_types';
}

Upvotes: 0

Related Questions