语法错误,意外的“$factory”(T_VARIABLE),期望函数(T_FUNCTI ON)或常量(T_CONST)

syntax error, unexpected '$factory' (T_VARIABLE), expecting function (T_FUNCTI ON) or const (T_CONST)

目前我正在使用 laravel 8.17。*

我正在尝试使用 faker 库添加数据,但出现错误“语法错误,意外的‘$factory’(T_VARIABLE),期望函数(T_FUNCTION)或常量(T_CONST)" 帮我解决这个错误

ProductFactory.php

<?php

  namespace Database\Factories;

  use App\Models\Model\Product;
  use Illuminate\Database\Eloquent\Factories\Factory;
  use Illuminate\Support\Str;
  use Faker\Generator as Faker;
  
   class ProductFactory extends Factory
   {
     /**
       * The name of the factory's corresponding model.
       *
       * @var string
       */
       protected $model =  \App\Models\Model\Product::class;

       /**
         * Define the model's default state.
         *
         * @return array

      public function definition()
      {
       return [
        //
       ];
      } */


     $factory->define(App\Models\Model\Product::class,function(Faker $faker){
    return [
        'name'=>$this->$faker->Word,
        'detail'=>$this->$faker->paragraph,
        'price'=>$this->$faker->numberBetween(99,999),
        'stock'=>$this->$faker->randomDigit,
        'discount'=>$this->$faker->numberBetween(2,30)
    ];
 });
}

**[在此处输入图片描述][1] [1]: https://i.stack.imgur.com/CvZND.png

Laravel 8 引入了基于 class 的模型工厂,因此示例定义必须类似于

<?php

  namespace Database\Factories;

  use App\Models\Model\Product;
  use Illuminate\Database\Eloquent\Factories\Factory;
  use Illuminate\Support\Str;
  use Faker\Generator as Faker;
  
   class ProductFactory extends Factory
   {
        /**
         * The name of the factory's corresponding model.
         *
         * @var string
         */
         protected $model =  \App\Models\Model\Product::class;

        /**
         * Define the model's default state.
         *
         * @return array
         */

        public function definition()
        {
            return [
                'name'=>$this->faker->Word,
                'detail'=>$this->faker->paragraph,
                'price'=>$this->faker->numberBetween(99,999),
                'stock'=>$this->faker->randomDigit,
                'discount'=>$this->faker->numberBetween(2,30)
            ];
        }
    }