Skip to content

Instantly share code, notes, and snippets.

@jongravois
Created April 22, 2020 16:20
Show Gist options
  • Save jongravois/756b4d31ff40a67e12c4afd2807cfbbe to your computer and use it in GitHub Desktop.
Save jongravois/756b4d31ff40a67e12c4afd2807cfbbe to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Livewire\Profile;
use App\Models\Office;
use App\User;
use Livewire\Component;
class UsersProfile extends Component
{
public $tab = 'profile';
public $userID, $user, $anniversary, $badge, $direct_line, $dob, $email, $extension, $first_name, $last_name, $manager_id, $office_id, $skype, $title;
public function mount($id)
{
$this->user = User::find($id);
$this->setVariables();
} // end function
public function render()
{
return view('livewire.profile.user-profile', [
'user' => $this->user,
'offices' => Office::all(),
'managers' => User::whereCanManage(true)->orderBy('last_name')->get()
]);
} // end function
public function tabber($tab)
{
$this->setVariables($this->user);
$this->tab = $tab;
} // end function
public function setVariables()
{
$this->badge = $this->user->badge;
$this->email = $this->user->email;
$this->title = $this->user->title;
$this->skype = $this->user->skype;
$this->direct_line = $this->user->cellphone;
$this->extension = $this->user->extension;
$this->anniversary = ($this->user->anniversary ? $this->user->anniversary->format('Y-m-d') : null);
$this->dob = ($this->user->dob ? $this->user->dob->format('Y-m-d') : null);
$this->first_name = $this->user->first_name;
$this->last_name = $this->user->last_name;
$this->manager_id = $this->user->manager_id;
$this->office_id = $this->user->office_id;
$this->userID = $this->user->id;
} // end function
public function updateProfile()
{
$data = $this->validate([
'anniversary' => 'date',
'badge' => 'present',
'first_name' => 'present',
'last_name' => 'present',
'direct_line' => 'present',
'dob' => 'date',
'email' => 'email',
'extension' => 'present',
'manager_id' => 'present',
'office_id' => 'present',
'skype' => 'present',
'title' => 'present',
]);
$refreshed = User::find($this->userID)->update($data);
$this->user = $refreshed;
$this->setVariables();
} // end function
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment