title: Laravel Inserting Empty to Form and Null Value to Database
body: <p>How to insert an empty value to input text and set it to null to the database, as I do this I'm having an error because the rows of the database do not have a value. How can I do this without an error?</p>
  
  <blockquote>
    <p>SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title'
    cannot be null (SQL: insert into <code>awards</code> (<code>title</code>, <code>description</code>,
    <code>awards_image</code>, <code>updated_at</code>, <code>created_at</code>) values (, , a:0:{},
    2018-11-28 10:29:35, 2018-11-28 10:29:35))</p>
  </blockquote>
  
  <p><strong><em>EDIT</em></strong>
  </p>
  
  <pre><code>&lt;?php
  
  foreach ($awards as $key =&gt; $values) {
      $awardsContent = new Award;
      $awardsContent-&gt;title = $request-&gt;title[$key];
      $awardsContent-&gt;description = $request-&gt;description[$key];
      $awardsContent-&gt;awards_image = $values;
      $awardsContent-&gt;save();
  }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public function store(Request $request)
  {
      $this-&gt;validate($request, [
          'title' =&gt; 'nullable',
          'description' =&gt; 'nullable',
          'awards_image.*' =&gt; 'image|nullable|max:1999'
      ]);
  
      $awards = [];
      if ($request-&gt;has('awards_image')) {
          foreach ($request-&gt;file('awards_image') as $key =&gt; $file) {
              $filenameWithExt = $file-&gt;getClientOriginalName();
              $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
              $extension = $file-&gt;getClientOriginalExtension();
              $fileNameToStore = $filename . '_' . time() . '.' . $extension;
              $path = $file-&gt;storeAs('public/awards_images', $fileNameToStore);
              array_push($awards, $fileNameToStore);
          }
          $fileNameToStore = serialize($awards);
      } else {
          $fileNameToStore = 'noimage.jpg';
      }
  
      $awardsContent = new Award;
      $awardsContent-&gt;title = $request-&gt;input('title');
      $awardsContent-&gt;description = $request-&gt;input('description');
      $awardsContent-&gt;awards_image = $fileNameToStore;
      $awardsContent-&gt;save();
  
      return redirect('/admin/airlineplus/awards')-&gt;with('success', 'Content Created');
  }
  </code></pre>