forked from eatvio/eatvio-infra
init commit
This commit is contained in:
100
app/Http/Livewire/Profile/PhotoForm.php
Normal file
100
app/Http/Livewire/Profile/PhotoForm.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Profile;
|
||||
|
||||
use Livewire\WithFileUploads;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PhotoForm extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
/**
|
||||
* The component's state.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $state = [];
|
||||
|
||||
/**
|
||||
* The new avatar for the user.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $photo;
|
||||
|
||||
public $isOnline = false;
|
||||
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Prepare the component.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function mount()
|
||||
{
|
||||
$this->state = $this->user->withoutRelations()->toArray();
|
||||
$lastActivity = DB::table('sessions')->select('last_activity')->where('user_id', $this->user->id)->first()->last_activity;
|
||||
$this->isOnline = (now()->unix() - $lastActivity) < 150;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user's profile information.
|
||||
*
|
||||
* @param \Laravel\Fortify\Contracts\UpdatesUserProfileInformation $updater
|
||||
* @return void
|
||||
*/
|
||||
public function updateProfileInformation(UpdatesUserProfileInformation $updater)
|
||||
{
|
||||
$this->resetErrorBag();
|
||||
|
||||
$updater->update(
|
||||
Auth::user(),
|
||||
$this->photo
|
||||
? array_merge($this->state, ['photo' => $this->photo])
|
||||
: $this->state
|
||||
);
|
||||
|
||||
$this->emit('saved');
|
||||
|
||||
}
|
||||
|
||||
public function updatedPhoto($newPhoto)
|
||||
{
|
||||
(Auth::user())->updateProfilePhoto($newPhoto);
|
||||
|
||||
$this->emit('saved');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user's profile photo.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteProfilePhoto()
|
||||
{
|
||||
Auth::user()->deleteProfilePhoto();
|
||||
|
||||
$this->emit('refresh-navigation-menu');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current user of the application.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUserProperty()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.profile.photo-form');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user