I have users
table with name, username, email, password, level
and profiles
table with name, profile_code, id_class
Logic
- profiles.name = users.name, profiles.profile_code = users.username = users.password
- So I can insert edit and delete on both table for that field
Code
Form controllerprotected $listeners=[ 'getModalId' ]; public function getModalId($idUpdate) { $this->idAction=$idUpdate; $idprofile=profile::find($this->idAction); $idUser=User::find($this->idAction); $this->profile_code=$idprofile->profile_code; $this->name=$idprofile->name; $this->class=$idprofile->id_class; $this->name=$this->name; $this->password=Hash::make($this->profile_code); $this->username=$this->profile_code; $this->email=$idUser->email; } public function save() { $data=[ 'profile_code'=>$this->profile_code, 'name'=>$this->name, 'id_class'=>$this->class, 'username'=>$this->nisn, 'password'=>Hash::make($this->profile_code), 'name'=>$this->name, 'email'=>$this->email, 'level'=>'profile' ]; $idData=['id'=>$this->idAction]; $idDataLogin=['id'=>$this->idAction]; $dataUpdateProfile=profile::where('id',$idData)->first(); $dataUpdateProfileLogin=User::where('id',$idDataLogin)->first(); if( $dataUpdateProfile == null && $dataUpdateProfileLogin == null){ profile::create($data); $this->resetVar($data); User::create($data); $this->resetVar($data); }else{ profile::find($idData)->first()->update($data); User::find($idDataLogin)->first()->update($data); } }
Component Controller
public function selectedItem($idAction, $action) { $this->idItem=$idAction; if ($action == 'delete'){ $this->emit('getModalId', $this->idItem); $this->dispatchBrowserEvent('openDeleteProfile'); }else{ $this->emit('getModalId', $this->idItem); $this->dispatchBrowserEvent('openUpdateProfile'); } } public function delete() { profile::destroy($this->idItem); User::destroy($this->idItem); $this->dispatchBrowserEvent('closeDeleteModal'); return redirect()->route('profile'); }
Profile Model
protected $table="profiles"; protected $fillable=[ 'profile_code', 'name', 'id_class' ];
没有评论:
发表评论