Home >php教程 >php手册 >laravel--Why are the attributes not defined in the model, but the values ​​are taken out? Where do these attributes come from?

laravel--Why are the attributes not defined in the model, but the values ​​are taken out? Where do these attributes come from?

WBOY
WBOYOriginal
2016-09-20 03:30:231619browse

Look at this code in laravel model,

<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> getLimitUsersAttribute()
  {
    </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->user_limit - <span style="color: #800080;">$this</span>-><span style="color: #000000;">user_count;
  }</span>

But there is no definition in the model,

那么user_limit和<span>user_count属性,是从哪里来的?<br>laravel本身一种机制,可以直接在模型当中调用数据库里字段,这个属性就是</span>Lesson模型对应的lession表里的2个字段

使用一下看看,控制器是这样来使用

方法在看一看

那么这样输出的结果应该是65,看看结果吧


<span><br><br></span>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn