laravel时间戳校验,默认为true校验,改为false则关闭
`public $timestamps = true;`
`get()`方法,获取数据
`find()`依据主键查找
`where()`方法,条件查询
~~~
public function userRead(){
return $this->where('username','xiaoming')->get();
}
~~~
查询`username`字段为小明的用户信息
~~~
return $this->where('age','>','20')->get();
~~~
查询`age`字段大于`20`的所有用户信息
~~~
public function userAdd(){
$this->username = xiaohong;
$this->age = 18;
$this->save();
}
~~~
插入一个用户
~~~
public function userAdd(){
$user_data = ['username' => 'user1','age' => 20];
$this->fill($user_data);
$this->save();
}
~~~
从表单中读取的数据是一个数组,用`fill()`方法存储
~~~
public function updateUser(){
$user->$this->find(1);
$user->username ='user2';
$user->age = 19;
$user->save();
}
~~~
~~~
public function userUpdate(){
$user = $this->find(1);
$user_data = ['username' => 'haha','age' => 20];
$user->update($userdata);
}
~~~
~~~
public function userDelete(){
$user->find(2);
$user->delete();
}
~~~
`has()`检查是否有一个键
`take(2)`取数组前两个
用户数据处理
`Request::only()`,only方法,过滤键名
`except()`除了