Exemplo n.º 1
0
 public function __construct()
 {
     parent::__construct();
     $this->factory = Factory::find($this->user->getKey());
     if (empty($this->factory)) {
         return $this->error('factory.failure_noexists');
     }
     $this->viewData['_factory'] = $this->factory;
 }
Exemplo n.º 2
0
 public function doAudit()
 {
     if ($this->audited) {
         return false;
     }
     $factory = Factory::find($this->fid);
     if (empty($factory)) {
         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::AGENT);
     $agent = Agent::find($user->getKey()) ?: Agent::create(['id' => $user->getKey(), 'name' => $this->name, 'phone' => $this->phone, 'address' => $this->address]);
     $user->roles()->sync([Role::where('name', Role::AGENT)->firstOrFail()->getKey()], false);
     $factory->agents()->sync([$agent->getKey()], false);
     $agent->brands()->sync($this->brand_ids, false);
     $this->audited = true;
     $this->save();
     return true;
 }
Exemplo n.º 3
0
 public function update(Request $request, $id)
 {
     $factory = Factory::find($id);
     if (empty($factory)) {
         return $this->failure_noexists();
     }
     $keys = 'name,address,phone';
     $data = $this->autoValidate($request, 'factory.store', $keys, $factory);
     $factory->update($data);
     return $this->success();
 }
Exemplo n.º 4
0
 public function __construct()
 {
     parent::__construct();
     $this->agent_ids = Factory::find($this->factory->getKey())->agent_ids()->toArray();
 }