亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

產(chǎn)品模塊中添加和刪除功能

asal 2019-03-30 10:12:23 310
abstrak:public function DoAdd(){    // 獲取提交出來(lái)的數(shù)據(jù)    $data = Request::param();    // 將產(chǎn)品名獨(dú)立出來(lái)    $title = $data['title'];    // 利用產(chǎn)品名作為查詢(xún)條件查詢(xún)對(duì)應(yīng)的數(shù)據(jù) &nbs



public function DoAdd()
{
   // 獲取提交出來(lái)的數(shù)據(jù)
   $data = Request::param();
   // 將產(chǎn)品名獨(dú)立出來(lái)
   $title = $data['title'];
   // 利用產(chǎn)品名作為查詢(xún)條件查詢(xún)對(duì)應(yīng)的數(shù)據(jù)
   $info = ProductModel::where('title', $title)->find();
   // 判斷是否查詢(xún)到相同的產(chǎn)品名稱(chēng)
   if ($info == true) {
       // 返回提示信息
       return ['res' => 0, 'msg' => '產(chǎn)品標(biāo)題重復(fù)!'];
   }
   // 加入添加時(shí)間
   $data['time'] = time();
   // 添加發(fā)布管理員
   $data['username'] = Session::get('username');
   // 實(shí)例化模型
   $product = new ProductModel();
   // 進(jìn)行添加并驗(yàn)證
   if ($product->save($data)) {
       // 返回提示信息
       return ['res' => 1, 'msg' => '發(fā)布成功!'];
   } else {
       // 返回提示信息
       return ['res' => 0, 'msg' => '發(fā)布失?。?#39;];
   }
}


public function del()
{
   // 獲取需要?jiǎng)h除的產(chǎn)品id
   $proId = Request::param('id');
   $product = new ProductModel();
   if ($product->destroy($proId)) {
       return ['res'=>1,'msg'=>'刪除成功!'];
   }

Guru membetulkan:天蓬老師Masa pembetulan:2019-03-30 10:21:18
Rumusan guru:在方法中, 盡可能避免直接使用new, $product = new ProductModel();, 可以通過(guò)對(duì)象注入, 或者 Facade 方式進(jìn)行調(diào)用

Nota Keluaran

Penyertaan Popular