2016-01-21 91 views
1

我有这种模式的客户:Laravel 5.1找雄辩返回null

<?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', ... 
     ... 

我无法理解的是: 当我试试这个:

$customer = Customer::all();     
dd($customer); 

我得到的结果

并尝试此操作时:

$customer = Customer::find(1);     
dd($customer); 

我收到null

+1

客户表的模式如何? –

+0

如果你正在使用softDelete为customers表添加'deleted_at'列? –

+0

模式::创建( '客户',函数(蓝图$表){ \t \t \t $表 - >增量( '身份证'); \t \t \t $表 - >字符串( '名',150); \t \t \t $表 - >串( '地址',255); \t \t \t表 - $>串( '电话',30); \t \t \t \t \t \t $表 - >串( '传真', 30); \t \t \t $ table-> softDeletes(); \t \t \t $ table-> timestamps(); \t \t \t \t \t}); – BKF

回答

1

随着$customer = Customer::find(1);你只是想让客户拥有主键“1”。

随着Customer::all();你得到你所有的客户。

你得到null的原因是因为你的数据库中没有任何id为1的客户(可能已被删除)。

+0

不,不是的,我解决了上述问题 – BKF

+0

那很好... ;) –