File: /var/www/admin.fixgini.com/app/Livewire/Profile/Update.php
<?php
namespace App\Livewire\Profile;
use App\Models\Shop;
use Livewire\Component;
use Illuminate\Support\Facades\Log;
class Update extends Component
{
public $user;
public $shop;
public $address;
protected $rules = [
"address"=> "required|string|max:200",
];
public function mount()
{
$this->user = auth()->user();
$this->shop = $this->address();
}
public function address()
{
$shop = Shop::where('user_id', $this->user->id)->first();
if ($shop) {
return $this->shop = $shop;
} else {
return $this->shop = null;
}
}
public function updateAddress()
{
try {
$shop = Shop::where('user_id', $this->user->id)->firstOrFail();
$this->validate();
$shop->update([
'address' => $this->address,
]);
session()->flash('status', 'Shop address updated successfully.');
return redirect()->to('/admin-settings');
} catch (\Throwable $th) {
$this->addError('address', 'Error updating shop address: ' . $th->getMessage());
}
}
public function render()
{
return view('livewire.profile.update');
}
}