title: How to declare $faker in the seed file in Laravel when overriding for argument to factory?
body: <p>I am trying to create multiple model of seeds like seedt1, seedt2, seedt3 with parameters for the sample.</p>
  <p><em><strong>I  am aware of factory states, i don't want to use it,i want to keep my factory model minimal and clean as possible.</strong></em></p>
  <p>i have my model factory:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  
  /** @var \Illuminate\Database\Eloquent\Factory $factory */
  
  use App\User;
  use App\Client;
  use App\Query;
  use App\Task;
  use Faker\Generator as Faker;
  
  ////////// Users factory //////////
  $factory-&gt;define('App\User', function (Faker $faker) {
      $faker-&gt;locale = 'fr_FR';
      return [
          'full_name' =&gt; $faker-&gt;name,
          'email' =&gt; $faker-&gt;unique()-&gt;safeEmail,
          'password' =&gt; bcrypt('secret'),
          'remember_token' =&gt; Str::random(10),
          'objective' =&gt; '0',
          'role_id' =&gt;1,
          'isActive' =&gt; '1',
          'img_path' =&gt;'user-lg.jpg',
      ];
  });
  
  ////////// Clients factory //////////
  $factory-&gt;define('App\Client', function ($faker) {
      $faker-&gt;locale = 'fr_FR';
      return [
          'name' =&gt; $faker-&gt;company,
          'legalname' =&gt; $faker-&gt;name,
          'legalname2' =&gt; $faker-&gt;name,
          'legalname3' =&gt; $faker-&gt;name,
          'email' =&gt; $faker-&gt;email,
          'address' =&gt; $faker-&gt;address,
          'country' =&gt; $faker-&gt;country,
          'website' =&gt; $faker-&gt;domainName,
          'telephone' =&gt; $faker-&gt;phoneNumber,
          'telephone2' =&gt; $faker-&gt;phoneNumber,
          'fax' =&gt; $faker-&gt;PhoneNumber,
          'other1' =&gt; $faker-&gt;email,
          'other2' =&gt; $faker-&gt;email,
          'other3' =&gt; $faker-&gt;email,
          'foundeddate' =&gt; $faker-&gt;dateTimeThisDecade,
          'crmregistered' =&gt; $faker-&gt;dateTimeThisYear,
          'comments' =&gt; $faker-&gt;realText($maxNbChars = 300, $indexSize = 2),
          'insurancenumber' =&gt; $faker-&gt;numberBetween($min = 80000, $max = 150000),
          'data1' =&gt; $faker-&gt;boolean($chanceOfGettingTrue = 50),
          'data2' =&gt; $faker-&gt;boolean($chanceOfGettingTrue = 50),
          'type_id' =&gt; $faker-&gt;numberBetween($min = 1, $max = 2),
          'isActive' =&gt; '1',
          'user_id' =&gt; $faker-&gt;numberBetween($min = 3, $max = 15),
          'img_path' =&gt;'imageUrl($width, $height, \'cats\')',
      ];
  });
  ////////// Queries factory //////////
  $factory-&gt;define('App\Query', function ($faker) {
      $faker-&gt;locale = 'fr_FR';
      return [
          'guests_no' =&gt; $faker-&gt;numberBetween($min = 50, $max = 500),
          'days_no' =&gt; $faker-&gt;numberBetween($min = 3, $max = 7),
          'value' =&gt; $faker-&gt;ean8,
          'arrival_date' =&gt; $faker-&gt;dateTimeInInterval($startDate = '+1 years', $interval = '+ 14 days', $timezone = null),
          'departure_date' =&gt; $faker-&gt;dateTimeInInterval($startDate = '+1 years', $interval = '+ 21 days', $timezone = null),
          'file_name' =&gt; $faker-&gt;numerify('dossier ######'),
          'file_number' =&gt; $faker-&gt;ean8,
          'facture_number' =&gt; $faker-&gt;creditCardNumber,
          'guide' =&gt; $faker-&gt;boolean($chanceOfGettingTrue = 50),
          'rentacar' =&gt; $faker-&gt;boolean($chanceOfGettingTrue = 50),
          'aerial' =&gt; $faker-&gt;boolean($chanceOfGettingTrue = 50),
          'user_id' =&gt; $faker-&gt;numberBetween($min = 3, $max = 15),
          'client_id' =&gt; $faker-&gt;numberBetween($min = 1, $max = 1000),
          'transport_type_id' =&gt; $faker-&gt;numberBetween($min = 1, $max = 3),
          'created_at' =&gt; $faker-&gt;dateTimeThisYear,
          'payment_status_id' =&gt; $faker-&gt;numberBetween($min = 1, $max = 3),
          'query_status_id' =&gt; $faker-&gt;numberBetween($min = 1, $max = 7),
          'query_type_id' =&gt; $faker-&gt;numberBetween($min = 1, $max = 3),
          'isActive' =&gt; '1',
          'notified' =&gt; $faker-&gt;boolean($chanceOfGettingTrue = 50),
      ];
  });
  ////////// Task factory //////////
  $factory-&gt;define('App\Task', function ($faker) {
      $faker-&gt;locale = 'fr_FR';
      return [
          'text' =&gt; $faker-&gt;realText($maxNbChars = 300, $indexSize = 2),
          'name' =&gt; $faker-&gt;name,
          'status' =&gt; $faker-&gt;ean8,
          'user_id' =&gt; $faker-&gt;numberBetween($min = 3, $max = 15),
          'query_id' =&gt; $faker-&gt;numberBetween($min = 1, $max = 500),
          'isActive' =&gt; '1',
          'query_status_id' =&gt; $faker-&gt;numberBetween($min = 1, $max = 7),
      ];
  });
  ////////// State sample factory //////////
  /*$factory-&gt;state(App\User::class, 'delinquent', function ($faker) {
      return [
          'account_status' =&gt; 'delinquent',
      ];
  });*/</code></pre>
  </div>
  </div>
  </p>
  <p>and my seed file:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  
  use Illuminate\Database\Seeder;
  
  class sampleT1 extends Seeder
  {
  
      public function run()
      {
  
          factory('App\User', 1)-&gt;create(['role_id' =&gt;'2',]); //1 financial user id 2
          factory('App\User', 3)-&gt;create(['role_id' =&gt;'4',]); //3 managers id 3-5
          factory('App\User', 5)-&gt;create(); //10 users id 6-10
          factory('App\Client', 300)-&gt;create(['user_id' =&gt; $faker-&gt;numberBetween($min = 3, $max = 10),]); //300 clients
          factory('App\Query', 1000)-&gt;create(['user_id' =&gt; $faker-&gt;numberBetween($min = 3, $max = 10), 'client_id' =&gt; $faker-&gt;numberBetween($min = 1, $max = 300),]); //300 queries
          factory('App\Task', 5000)-&gt;create(['user_id' =&gt; $faker-&gt;numberBetween($min = 3, $max = 10), 'query_id' =&gt; $faker-&gt;numberBetween($min = 1, $max = 250),]); //5000 tasks
          //factory('App\User', 50)-&gt;states('premium', 'delinquent')-&gt;create();
  
      }
  }</code></pre>
  </div>
  </div>
  </p>
  <p>when i run my seed with : <code>php artisan db:seed --class=sampleT1</code></p>
  <p>i get result:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>deployer@debdaddytp:/var/www/mice$ php artisan db:seed --class=sampleT1
  
     ErrorException 
  
    Undefined variable: faker
  
    at database/seeds/sampleT1.php:20</code></pre>
  </div>
  </div>
  </p>
  <p>obviously the variable of faker is not inherited from the model factory, how should i declare it in my seed for this to work?</p>