Exemplo n.º 1
0
 /**
  * Creates a new Tags model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tags();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     // dd($request);
     if ($request->tID) {
         $tag = Tags::wheretid($request->tID)->first();
     } else {
         $tag = new Tags();
     }
     $tag->tName = $request->tName;
     $tag->tDescription = $request->tDes;
     $tag->tIsActive = is_null($request->active) ? 0 : 1;
     $tag->save();
     return Redirect::action('admin\\tag@index');
 }
Exemplo n.º 3
0
 private function _setTags($tags_str, $post_id)
 {
     PostTag::where('post_id', $post_id)->delete();
     $tags = explode(', ', $tags_str);
     foreach ($tags as $tag) {
         if (trim($tag) == '') {
             continue;
         }
         $tag = mb_strtolower($tag);
         $dbtag = Tags::where('tag', 'like', $tag)->first();
         if (empty($dbtag)) {
             $dbtag = new Tags();
             $dbtag->tag = strip_tags($tag);
             $dbtag->save();
         }
         $post_tag = new PostTag();
         $post_tag->post_id = $post_id;
         $post_tag->tag_id = $dbtag->id;
         $post_tag->save();
     }
 }
Exemplo n.º 4
0
 public function postTags(Request $req)
 {
     $rules = ['tag_name' => ['required', 'min:2']];
     $valid = Validator::make($req->input(), $rules);
     if (!$valid->fails()) {
         $tag = new Tags();
         $tag->tag_name = strtolower(str_slug($req->input('tag_name')));
         if ($tag->save()) {
             return redirect()->back()->with('msg', 'Successfully Saved Tag');
         }
     } else {
         return redirect()->back()->withErrors($valid->errors());
     }
 }