コード例 #1
0
ファイル: DatabaseSeeder.php プロジェクト: ddingchen/yilian
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     factory(Maker::class, 3)->create();
     factory(Buyer::class, 3)->create();
     factory(Commodity::class, 5)->create();
     factory(Goods::class, 5)->create();
     $goods = Goods::all()->random(2);
     $exJoinings = [];
     $inJoinings = [];
     foreach ($goods->keys() as $key) {
         $exJoinings[$key] = $this->randJoiningsFoxExternalOrder();
         $inJoinings[$key] = $this->randJoiningsForInternalOrder();
     }
     $externalOrder = new ExternalOrder();
     $externalOrder->contract_no = '15EL1166';
     $externalOrder->sign_date = Carbon::now();
     $externalOrder->buyer()->associate(Buyer::all()->random());
     $externalOrder->save();
     $externalOrder->goods()->saveMany($goods->all(), $exJoinings);
     $internalOrder = new InternalOrder();
     $internalOrder->externalOrder()->associate($externalOrder);
     $internalOrder->maker()->associate(Maker::all()->random());
     $internalOrder->save();
     $internalOrder->goods()->saveMany($goods->all(), $inJoinings);
 }
コード例 #2
0
 public function index(Manager $fractal, BuyerTransformer $buyerTransformer)
 {
     // show all
     $records = Buyer::all();
     $collection = new Collection($records, $buyerTransformer);
     $data = $fractal->createData($collection)->toArray();
     return $this->respond($data);
 }
コード例 #3
0
ファイル: ModelFactory.php プロジェクト: ddingchen/yilian
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(User::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'remember_token' => str_random(10)];
});
$factory->define(Buyer::class, function (Faker\Generator $faker) {
    return ['name' => str_random(5)];
});
$factory->define(Maker::class, function (Faker\Generator $faker) {
    return ['name' => str_random(10)];
});
$factory->define(Commodity::class, function (Faker\Generator $faker) {
    return ['name' => str_random(10)];
});
$factory->define(Goods::class, function (Faker\Generator $faker) {
    return ['specification' => str_random(3) . '-' . rand(100, 999), 'commodity_id' => Commodity::all()->random()->id];
});
$factory->define(ExternalOrder::class, function (Faker\Generator $faker) {
    return ['buyer_id' => Buyer::all()->random()->id];
});
$factory->define(InternalOrder::class, function (Faker\Generator $faker) {
    return ['maker_id' => Maker::all()->random()->id];
});