$ php artisan make:model Models/Issue
class Issue extends Model
{
//指定表名
protected $table = 'article2';
//指定主键
protected $primaryKey = 'article_id';
//是否开启时间戳
protected $timestamps = false;
//设置时间戳格式为Unix
protected $dateFormat = 'U';
//过滤字段,只有包含的字段才能被更新
protected $fillable = ['title','content'];
//隐藏字段
protected $hidden = ['password'];
}
class Issue extends Model
{
protected $fillable = ['title'];
}
use AppModelsIssue
Issue::create(['title' => 'PHP Lover'])
Issue::create(['title' => 'Rails and Laravel'])
Issue::all()
use AppModelsIssue;
$issues = Issue::orderBy('created_at', 'desc')
->take(2)
->get();
use AppModelsIssue;
Issue::create($request->all());
use AppModelsIssue;
Issue::destroy($id);
use AppModelsIssue;
$issue = Issue::find($id);
$issue->update($request->all());