Reputation: 1366
I've this model Customer :
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\softDeletes;
class Customer extends Model
{
use SoftDeletes;
protected $table = 'customers';
public $timestamps = true;
protected $dates = ['deleted_at'];
protected $fillable = ['name', ...
...
What I can't understand is : When I try this :
$customer = Customer::all();
dd($customer);
I get results
and when trying this :
$customer = Customer::find(1);
dd($customer);
I get null
.
Upvotes: 1
Views: 1134
Reputation: 4023
With that $customer = Customer::find(1);
you're just trying to get the customer that have primary key "1".
With Customer::all();
you get all of your customer.
The reason you got null is because you haven't any customer with id 1 in your database (maybe has been deleted).
Upvotes: 1