示例#1
0
 public function update(Request $request, $id)
 {
     $params = $request->all();
     $subject = Subject::find($id);
     if ($subject != null) {
         if ($request->hasFile('coverImage')) {
             $file = $request->file('coverImage');
             $fileName = md5(uniqid()) . '.' . $file->getClientOriginalExtension();
             $file->move(base_path() . '/public/upload', $fileName);
             $params['cover'] = '/upload/' . $fileName;
         }
         unset($params['coverImage']);
         unset($params['_token']);
         $chooseThemes = $params['chooseThemes'];
         unset($params['chooseThemes']);
         foreach ($params as $n => $p) {
             $subject->{$n} = $p;
         }
         $subject->save();
         SubjectThemes::where('subject_id', $subject->id)->delete();
         $len = strlen($chooseThemes);
         if ($len > 0) {
             $chooseThemes = substr($chooseThemes, 0, $len - 1);
             $chooseThemes = explode(',', $chooseThemes);
             foreach ($chooseThemes as $i) {
                 $subjectThemes = new SubjectThemes();
                 $subjectThemes->subject_id = $subject->id;
                 $subjectThemes->theme_id = $i;
                 $subjectThemes->save();
             }
         }
     }
     return redirect()->action('Admin\\SubjectController@show');
 }
示例#2
0
 public function delete($id)
 {
     $sub = SubjectThemes::where('theme_id', $id)->first();
     if ($sub != null) {
         $ret['meta']['code'] = 0;
         $ret['meta']['error'] = '删除失败,该商品已绑定到专题,对应id为' . $sub->subject_id;
         echo json_encode($ret);
         return;
     }
     $home = Home::where('item_id', $id)->where('type', 1)->first();
     if ($home != null) {
         $ret['meta']['code'] = 0;
         $ret['meta']['error'] = '删除失败,该主题已绑定到首页,对应id为' . $home->id;
         echo json_encode($ret);
         return;
     }
     Themes::find($id)->delete();
     $ret['meta']['code'] = 1;
     echo json_encode($ret);
 }
示例#3
0
文件: Subject.php 项目: Lazybin/huisa
 public function getThemesAttribute()
 {
     $goods = SubjectThemes::where('subject_id', $this->id)->get()->toArray();
     return $goods;
 }