public function __construct() { parent::__construct(); $this->agent = Agent::find($this->user->getKey()); if (empty($this->agent)) { return $this->error('agent.failure_noexists'); } $this->stores_ids = Agent::find($this->agent->getKey())->store_ids()->toArray(); $this->viewData['_agent'] = $this->agent; }
public function addToFavorites(Request $request) { $agent = Agent::find($request->get('agent')); $user_sender_id = Auth::user()->id; $user_receiver_id = $agent->user->id; if ($user_sender_id == $user_receiver_id) { return Redirect::back()->with('warn_message', 'Cannot favorite your own post'); } FavoriteAgent::create(['user_id' => $user_sender_id, 'agent_id' => $agent->id]); Notifynder::category('user.favorite')->from($user_sender_id)->to($user_receiver_id)->url('http://homestead.app/agents/' . $agent->id)->send(); return Redirect::back(); }
public function doAudit() { if ($this->audited) { return false; } $agent = Agent::find($this->aid); if (empty($agent)) { return false; } $user = (new User())->get($this->username) ?: (new User())->add(['username' => $this->username, 'password' => substr($this->idcard, -6), 'realname' => $this->realname, 'idcard' => $this->idcard, 'phone' => $this->username], Role::STORE); $store = Store::find($user->getKey()) ?: Store::create(['id' => $user->getKey(), 'name' => $this->name, 'phone' => $this->phone, 'address' => $this->address]); $user->roles()->sync([Role::where('name', Role::STORE)->firstOrFail()->getKey()], false); $agent->stores()->sync([$store->getKey()], false); $store->brands()->sync($this->brand_ids, false); $this->audited = true; $this->save(); return true; }
/** * Display a listing of the resource. * * @return Response */ public function index(Request $request) { $agent_id = Session::get('AGENT_ACCESS_ID'); $data = array(); $data['record'] = Agent::find($agent_id); if ($request->isMethod('post')) { $first_name = $request->first_name; $last_name = $request->last_name; $phone = $request->phone; $password = $request->password; $update_arr = array('first_name' => $first_name, 'last_name' => $last_name, 'phone' => $phone); if ($password != '') { $update_arr['password'] = md5($password . Config::get('constants.SITENAME')); } Agent::where('id', '=', $agent_id)->update($update_arr); Session::put('ADMIN_ACCESS_FNAME', $first_name); Session::put('ADMIN_ACCESS_LNAME', $last_name); return redirect::route('agent_profile')->with('successmsg', 'Profile is updated successfully'); } return view('agent/profile', $data); }
public function destroy(Request $request, $id) { empty($id) && !empty($request->input('id')) && ($id = $request->input('id')); $id = (array) $id; $factory_brand_ids = $this->factory->brand_ids()->toArray(); foreach ($id as $v) { $agent = Agent::find($v); //删除所属门店下的相关品牌列表 $original_brand_ids = $agent->brands()->whereIn('brands.id', $factory_brand_ids)->get(['brands.id'])->pluck('id'); foreach ($agent->stores as $store) { $store->brands()->detach($original_brand_ids); } //删除厂商关联 $agent->factories()->detach($this->factory->getKey()); //删除品牌关联 $agent->brands()->detach($factory_brand_ids); } return $this->success('', count($id) > 5, compact('id')); }
public function update(Request $request, $id) { $agent = Agent::find($id); if (empty($agent)) { return $this->failure_noexists(); } $keys = 'name,address,phone,factory_ids,brand_ids'; $data = $this->autoValidate($request, 'agent.store', $keys, $agent); $factory_ids = array_pull($data, 'factory_ids'); $brand_ids = array_pull($data, 'brand_ids'); $agent->update($data); $agent->factories()->sync($factory_ids); $agent->brands()->sync($brand_ids); return $this->success(); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $agent = Agent::find($id); $agent->delete(); return Redirect::route('agent_management')->with('success', 'Agent has been deleted successfully!'); }