【问题标题】:How to get the Coloumn Name from Model rather than Primary Key如何从模型而不是主键中获取列名
【发布时间】:2014-12-25 04:38:34
【问题描述】:

这是我们在定义protected $primaryKey = 'AutoID'; 主键时通常如何调用数据。

但是如果我想要另一个字段而不是主键,我该怎么做呢?

$AuthorData = AuthorModel::find(1);
$AuthorData = AuthorModel::find(1);// How to get AuthorID='1'

【问题讨论】:

    标签: php laravel laravel-4


    【解决方案1】:

    如果它是唯一的条目(否则这没有多大意义):

    $AuthorData = AuthorModel::where('AuthorID', 1)->first();
    

    【讨论】:

      猜你喜欢
      • 2014-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      • 1970-01-01
      相关资源
      最近更新 更多