/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     /*
             $brand_name_array = $request->get('brand_name');
             Models used fo registering a merchant
             User, Bank, Buyer, Address, Merchant, Brand, Website and Director
     */
     $user = new User();
     $user_model = $user->store($request);
     //return new user record in db
     $bank = new Bank();
     $bank_model = $bank->store($request);
     if ($request['indication'] == 'buyer') {
         return "no functionality implemented";
         $buyer = new Buyer();
         $buyer_model = $buyer->store($request, $user_model);
     }
     if ($request['indication'] == 'merchant') {
         //TODO: for adding address first create address then add address id to merchant table
         //country_id   => working
         $address = new Address();
         $address_model = $address->store($request);
         // user_id, country_id, address_id, bank_id => working
         $user_as_merchant = new Merchant();
         $user_as_merchant_model = $user_as_merchant->store($request, $user_model, $bank_model, $address_model);
         /*
          * Document table
          */
         $documents = new Document();
         $documents_model = $documents->store($request, $user_as_merchant_model);
         //todo: add brand
         //1)create merchant and get model
         //2)create all brand and get all models
         //3)sync merchant model with brand models in merchantbrand table
         $brand = new Brand();
         $brand_models = $brand->store($request, $user_as_merchant_model, $address_model);
         //now syncing
         $user_as_merchant_model->attachBrands($user_as_merchant_model, $brand_models);
         //http://laravel.com/docs/5.1/eloquent-relationships#inserting-many-to-many-relationships
         //for storing web sites in "merchantwebsite" table
         //first create merchant and get id
         //then create websites and get website model array like director
         //then attach merchant with each website id
         $website = new Website();
         $website_models = $website->store($request);
         //attachment with merchant in "merchantwebsite" table
         $user_as_merchant->attachWebsites($website_models, $user_as_merchant_model);
         $director = new Director();
         $director_model = $director->store($request, $user_as_merchant_model);
         /*save all FKs of directors & merchants to merchantdirectos tables */
         $user_as_merchant_model->attachDirectors($director_model, $user_as_merchant_model);
         \Session::flash(Config::get('messages.key.name'), $this->messageHandler->success('merchantRegistered', null, null, true, true, true));
     }
     return redirect()->back();
 }