Blogger Information
Blog 9
fans 0
comment 0
visits 7498
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
laravel基础2(模型)
高杰
Original
576 people have browsed it

1、创建模型,用artisan创建模型

php artisan make:model Article

2、模型使用

在controller中使用模型

use App\article;    //先引用模型

public function dbmodel(Article $article){

    $article->get()->all();    //查询出来的结果为对象

    $article->get()->toArray();    //查询出来的结果直接转为数组

}//如报指定的数据表articles不存在,解决方法,第一修改数据库名称,第二在模型中指定$this->tablename = 'article'

模型查询出来的数据显示摸板上:查询出来的数据为对象,输出的时候,需要用 $val->username;如果想在摸板输出数组,需要将循环的数据进行(array)转换。

Correcting teacher:WJWJ

Correction status:qualified

Teacher's comments:写的不错,认真!
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post