GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
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');
    }
}