public function getCategoryTemplateList($categoryId)
 {
     $templates = Template::where('category_id', '=', $categoryId)->get();
     return $templates;
 }
 protected function initUser($user)
 {
     $default = Template::where('name', '=', 'default')->first()->id;
     $cv = CV::create(['user_id' => $user->id, 'template_id' => $default]);
     UserSeeder::seedCv($cv);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     // Grab our template
     $tg = TemplateGroup::findOrFail($id);
     $templates = $tg->templates;
     // Make an array of template IDs: existing templates and request templates.
     $currentTemplates = [];
     foreach ($templates as $template) {
         $currentTemplates[] = $template->template_id;
     }
     $newTemplates = array_keys($request->templates);
     $templatesDelete = array_diff($currentTemplates, $newTemplates);
     $templatesAdd = array_diff($newTemplates, $currentTemplates);
     foreach ($templatesDelete as $td) {
         $tpl = Template::where('template_id', '=', $td)->where('template_group_id', '=', $tg->id)->first();
         $tpl->delete();
     }
     foreach ($templatesAdd as $ta) {
         $newTemplate = new Template(['template_id' => $ta, 'size' => 'SaaS' == $request->type ? '0' : $request['templateSize'][$ta], 'price' => '0']);
         $tg->templates()->save($newTemplate);
         unset($newTemplate);
     }
     // Update the template group record
     $tg->name = $request->name;
     $tg->type = $request->type;
     // Check to see if we have a new image to work with
     if ($request->hasFile('display_img')) {
         // Save file somewhere useful
         $path = public_path() . '/img/';
         $filename = $request->file('display_img')->getFilename() . '.' . $request->file('display_img')->guessExtension();
         $request->file('display_img')->move($path, $filename);
         $tg->display_img = $filename;
     }
     $tg->save();
     flash()->success('Successfully updated template group: ' . $tg->name);
     return back();
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     // Currencies
     view()->composer(array('customers.edit', 'customer_invoices.create', 'companies.edit', 'customer_groups.create', 'customer_groups.edit'), function ($view) {
         $view->with('currencyList', \App\Currency::lists('name', 'id'));
     });
     // Customer Groups
     view()->composer(array('customers.edit'), function ($view) {
         $view->with('customer_groupList', \App\CustomerGroup::lists('name', 'id'));
     });
     // Payment Methods
     view()->composer(array('customers.edit', 'customer_invoices.create', 'customer_groups.create', 'customer_groups.edit'), function ($view) {
         $view->with('payment_methodList', \App\PaymentMethod::lists('name', 'id'));
     });
     // Sequences
     view()->composer(array('customers.edit', 'customer_invoices.create', 'customer_groups.create', 'customer_groups.edit'), function ($view) {
         $view->with('sequenceList', \App\Sequence::lists('name', 'id'));
     });
     // Invoice Template
     view()->composer(array('customers.edit', 'customer_invoices.create', 'customer_groups.create', 'customer_groups.edit'), function ($view) {
         $view->with('customerinvoicetemplateList', \App\Template::where('model_name', '=', 'CustomerInvoice')->lists('name', 'id'));
     });
     // Carriers
     view()->composer(array('customers.edit', 'customer_invoices.create', 'customer_groups.create', 'customer_groups.edit'), function ($view) {
         $view->with('carrierList', \App\Carrier::lists('name', 'id'));
     });
     // Sales Representatives
     view()->composer(array('customers.edit', 'customer_invoices.create'), function ($view) {
         $view->with('salesrepList', \App\SalesRep::select(DB::raw('concat (firstname," ",lastname) as name, id'))->lists('name', 'id'));
     });
     // Price Lists
     view()->composer(array('customers.edit', 'customer_groups.create', 'customer_groups.edit'), function ($view) {
         $view->with('price_listList', \App\PriceList::lists('name', 'id'));
     });
     // Warehouses
     view()->composer(array('products.create', 'stock_movements.create', 'configurationkeys.key_group_2', 'customer_invoices.create'), function ($view) {
         $whList = \App\Warehouse::with('address')->get();
         $list = [];
         foreach ($whList as $wh) {
             $list[$wh->id] = $wh->address->alias;
         }
         $view->with('warehouseList', $list);
         // $view->with('warehouseList', \App\Warehouse::lists('name', 'id'));
     });
     // Taxes
     view()->composer(array('customer_invoices.create', 'products.create', 'products.edit'), function ($view) {
         $view->with('taxList', \App\Tax::orderby('percent', 'desc')->lists('name', 'id'));
     });
     view()->composer(array('products.create', 'products.edit', 'customer_invoices.create'), function ($view) {
         $view->with('taxpercentList', \App\Tax::lists('percent', 'id'));
     });
     // Languages
     view()->composer(array('users.create', 'users.edit'), function ($view) {
         $view->with('languageList', \App\Language::lists('name', 'id'));
     });
     // Categories
     view()->composer(array('products.create', 'products._panel_main_data'), function ($view) {
         $view->with('categoryList', \App\Category::orderby('name', 'asc')->lists('name', 'id'));
     });
     // Stock Movement Types
     view()->composer(array('stock_movements.index', 'stock_movements.create'), function ($view) {
         $view->with('movement_typeList', \App\StockMovement::stockmovementList());
     });
 }