Esempio n. 1
0
 /**
  * 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);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(ExternalOrderPostRequest $request)
 {
     // store basic information
     $order = new ExternalOrder($request->only(['contract_no', 'sign_date']));
     $order->buyer()->associate(Buyer::find($request->input('buyer_id')));
     $order->save();
     // store commodities and specification
     if ($request->input('unknow_goods')) {
         $inputForNewGoods = [];
         foreach ($request->input('unknow_goods') as $input) {
             $goods = $this->retrieveGoods($input['commodity'], $input['specification']);
             $inputForNewGoods[$goods->id] = collect($input)->except(['commodity', 'specification'])->all();
         }
         $order->goods()->sync($inputForNewGoods);
     }
     return redirect()->route('external_order.show', $order->id);
 }