title: Laravel 6 - `Undefined variable: value` only error in the first time
body: <p>In the first time I want to save data to database from table this error appear.</p>
  
  <blockquote>
    <p>ErrorException
        Undefined variable: value</p>
  </blockquote>
  
  <p>so I have to manually input the data from <code>tinker</code> or <code>mysql</code></p>
  
  <p>My Controller</p>
  
  <pre><code>public function store(Request $request)
  
  {
  
      $validateData = $request-&gt;validate([
  
          'name_device_type' =&gt; 'required|max:255',
  
          'signature' =&gt; 'Nullable'
  
      ]);
  
  
  
      $id = DeviceType::getidDeviceTypes();
  
      foreach ($id as $value);   // Error happend in this line.
  
      $lastdevicetypeId = $value-&gt;id;
  
      $newdevicetypeId = $lastdevicetypeId + 1;
  
      $GetnewdevicetypeId = sprintf('DT%04d', $newdevicetypeId);
  
  
  
      $devicetypes = new DeviceType();
  
      $devicetypes-&gt;idDeviceType = $GetnewdevicetypeId;
  
      $devicetypes-&gt;name_device_type = $request-&gt;input('name_device_type');
  
      $devicetypes-&gt;signature = $request-&gt;input('signature');
  
      $devicetypes-&gt;save();
  
  
  
      return redirect('/devicetypes')-&gt;with('success', 'New Device Type is added');
  
  }
  </code></pre>
  
  <p>My Migration table</p>
  
  <pre><code>public function up()
      {
          Schema::create('device_types', function (Blueprint $table) {
              $table-&gt;bigIncrements('id');
              $table-&gt;string('idDeviceType');
              $table-&gt;string('name_device_type');
              $table-&gt;mediumText('signature');
              $table-&gt;timestamps();
          });
      }
  </code></pre>
  
  <p>My create.blade.php</p>
  
  <pre><code>{!! Form::open(['action' =&gt; 'DeviceTypesController@store', 'method' =&gt; 'POST']) !!}
          &lt;div class="form-group"&gt;
              {!! Form::label('name_device_type', 'Type Device'); !!}
              {!! Form::text('name_device_type', '', ['class' =&gt; 'form-control', 'placeholder' =&gt; 'Type Device']); !!}
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              {!! Form::label('signature', 'Signature (Optional)'); !!}
              {!! Form::textarea('signature', '', ['id' =&gt; 'classic-ckeditor5', 'class' =&gt; 'form-control', 'placeholder' =&gt; 'Signature']); !!}
          &lt;/div&gt;
          {{ Form::button('&lt;i class="far fa-save"&gt;&lt;/i&gt; Submit', ['type' =&gt; 'submit', 'class' =&gt; 'btn btn-info'] )  }}
      {!! Form::close() !!}
  </code></pre>
  
  <p>the Model </p>
  
  <pre><code>class DeviceType extends Model
  {
      // Table Name
      protected $table = 'device_types';
      // Primary Key
      protected $primaryKey = 'idDeviceTypes';
      // Timestamps
      public $timestamps = true;
  
      public $incrementing = false;
  
      public static function getidDeviceType(){
          return $getidDeviceType = DB::table('device_types')-&gt;orderBy('id','desc')-&gt;take(1)-&gt;get();
      }
  }
  </code></pre>
  
  <p>But if the table has data this error disappear, also this error will appear again if I remove every data and made the table empty.</p>