title: Laravel: Setting a Default Value for Blank/Null Input
body: <p>This is the code in the migration:</p>
  
  <pre><code>$table-&gt;string('role')-&gt;default('Standard');
  </code></pre>
  
  <p>When I leave the input box blank, it gives me an error:  </p>
  
  <blockquote>
    <p>"SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'role' cannot be null</p>
  </blockquote>
  
  <p>How do we set the default value to "Standard" if the input box is left blank?</p>
  
  <p>Code for Controller</p>
  
  <pre><code> public function store(Request $request)
      {
          //return ['message' =&gt; 'I have your data'];
          $request-&gt;validate([
              'firstname' =&gt; 'required|string|max:191',
              'lastname' =&gt; 'required|string|max:191',
              'email' =&gt; 'required|string|email|max:191|unique:users',
              'password' =&gt; 'required|string|min:6',
          ]);
          return User::create([
          'firstname' =&gt; $request['firstname'],
          'lastname' =&gt; $request['lastname'],
          'email' =&gt; $request['email'],
          'phone' =&gt; $request['phone'],
          'role' =&gt; $request['role'],
          'usernotes' =&gt; $request['usernotes'],
          'password' =&gt; Hash::make($request['password']), //make sure to import Hash: use Illuminate\Support\Facades\Hash;
          'created_by' =&gt; $request['created_by'],
          'updated_by' =&gt; $request['updated_by'],
      ]);
      }
  </code></pre>