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()`除了