Model: It is recommended to change the method name
public function goods_find(){ // $find = Goods::find(6); $find = Goods::where('id',27)->find(); return $find; } public function goods_select(){ // $select = Goods::select(); // $select = Goods::select(6); $select = Goods::where('id','>',7)->select(); // toArray方法将当前的模型实例输出为数组 return $select->toArray(); } public function goods_create(){ $create = Goods::create([ 'cat' => 3, 'title' => '新商品', 'price' => '59.99', 'add_time' => time() ]); echo $create->id; // 可以直接获取自增id return $create; } public function goods_update(){ # 更新方式一(静态方法修改数据,返回的是当前模型的对象实例) // $update=Goods::update( // ['price'=>'99.99'], // ['id'=>22], // ); // return $update; # 更新方式二(这种方式是最佳的更新方式) $user=Goods::find(23); $user->price='102.99'; $save=$user->save(); return $save; } public function goods_delete(){ # 删除方法1(静态方法删除数据,返回的是当前模型的对象实例) $delete = Goods::where('id',3)->delete(); # 删除方法2( 根据主键删除) // $delete = User::destroy(4); return $delete; }
Support one
What's wrong with this?