title: Laravel Using Schedule to create entries every week for multiple users
body: <p>I am trying to auto generate multiple entries, one for each user every Monday morning at 07:00.</p>
  
  <p>Also it needs to check that an entry doesn't exist as the users can create there own if needed, I already validate manual creation with Requests timesheetRequest.php</p>
  
  <p>Console/Commands/AddSheets.php</p>
  
  <pre><code>&lt;?php
  
  namespace App\Console\Commands;
  
  use Illuminate\Console\Command;
  use App\Models\User;
  use Carbon\Carbon;
  use DB;
  
  class AddSheets extends Command
  {
  protected $signature = 'add:sheets';
  
  protected $description = 'Generate new timesheet for all active users';
  
  public function handle()
  {
      /**
       * get users where active
       * if does not exist, create a new timesheet for each user for current week 2018-11 W/C 24-03 MS
       */
      $users = User::with('profile')-&gt;where('status_id', '1')-&gt;get();
      foreach ($users as $user) {
          $currentweek = Carbon::now()
              -&gt;year . '-' . Carbon::now('w')
              -&gt;weekOfYear . ' W/C ' . Carbon::now()
              -&gt;day . '-' . Carbon::now()
              -&gt;month . ' ' . $user-&gt;profile-&gt;code();
          DB::table('timesheets')-&gt;insert([
              'name' =&gt; $currentweek,
              'status_id' =&gt; 1,
              'user_id' =&gt; $user-&gt;id
          ]);
      }
      $this-&gt;info('Add:Sheets Command Run successfully!');
  }
  }
  </code></pre>
  
  <p>with</p>
  
  <p>Kernel.php</p>
  
  <pre><code>&lt;?php
  
  namespace App\Console;
  
  use Illuminate\Console\Scheduling\Schedule;
  use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
  use App\Models\User;
  use Carbon\Carbon;
  use DB;
  
  class Kernel extends ConsoleKernel
  {
  
  protected $commands = [
      Commands\AddSheets::class
  ];
  
  protected function schedule(Schedule $schedule)
  {
      $schedule-&gt;command('add:sheets')-&gt;weekly()-&gt;mondays('07:00');
  }
  
  protected function commands()
  {
      require base_path('routes/console.php');
  }
  }
  </code></pre>
  
  <p>When I run</p>
  
  <pre><code>php artisan add:sheets
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>In Builder.php line 2445:
  
  Call to undefined method Illuminate\Database\Query\Builder::code()
  </code></pre>
  
  <p>But I am unsure what this means and can't see anything in the source code to suggest anything other than line 2445 is the error message for an exception.</p>
  
  <p>I am now at a loss.</p>
  
  <p>please help</p>