forked from eatvio/eatvio-infra
init commit
This commit is contained in:
52
app/Http/Livewire/Profile/DescriptionForm.php
Normal file
52
app/Http/Livewire/Profile/DescriptionForm.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Profile;
|
||||
|
||||
use App\Models\UserDetailz;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DescriptionForm extends Component
|
||||
{
|
||||
public $description = "";
|
||||
public $user;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->initDetailzIfNeeded();
|
||||
$this->description = $this->user->detailz->additional_info ?? "";
|
||||
}
|
||||
|
||||
public function updatedDescription($value)
|
||||
{
|
||||
$userDetailz = $this->user->detailz;
|
||||
|
||||
$userDetailz->additional_info = $value;
|
||||
$userDetailz->save();
|
||||
}
|
||||
|
||||
private function initDetailzIfNeeded()
|
||||
{
|
||||
$curUserDetailez = UserDetailz::firstOrNew(
|
||||
['user_id'=> $this->user->id],
|
||||
[
|
||||
'about_alergy' => '',
|
||||
'about_taking_pils' => '',
|
||||
'about_sport_hobbies' => '',
|
||||
'favorite_foods' => '',
|
||||
'unfavorite_foods' => '',
|
||||
'additional_info' => ''
|
||||
]
|
||||
);
|
||||
|
||||
if (is_null($curUserDetailez->id)) {
|
||||
$curUserDetailez->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.profile.description-form');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user