title: Storing a new post tag if it doesn't exist in the table?
body: <p>I have a single input field (using select2 plugin) in a blog post form which allow user to insert post tags from existing tags in the table or create new ones and store them in the Tag table and also attach them to the post when they hit submit post button. I've managed to get this work by filtering the input with <code>array_filter()</code>, if the input is <code>!is_numeric</code> the input will first get stored in Tag table and then attach the id to the post. </p>
  
  <p>The problem with this is that it's not working when the new tag from the input is in full numeric type, like <code>2017</code> tag. Is there a solution to get this working so the new tag is not limited to string only but also numeric type ? and if possible, I don't want to use any package for this.</p>
  
  <p>The post store method :</p>
  
  <pre><code>public function store(PostsReq $request) {
          $input = $request-&gt;all();
          $post = Post::create($input);
  
          //Handle the tags
          $getTags = $request-&gt;input('tagspivot');
          $oldTags = array_filter($getTags, 'is_numeric');
          $newTags = array_filter($getTags, function($item) {
              return !is_numeric($item);
          });
          foreach ($newTags as $newTag) {
              if ($tag = Tag::create(['title' =&gt; strtolower(trim($newTag))])) {
                  $oldTags[] = $tag-&gt;id;
              }
          }
          $post-&gt;tags()-&gt;attach($oldTags);
  
          // Upload Image
          if ($request-&gt;hasFile('image')) {
              $input['image'] = $this-&gt;uploadImage($request, $post);
          }
          return redirect()-&gt;route('postindex')-&gt;with($this-&gt;postStoreSuccess);
      }
  </code></pre>