Untitled

mail@pastecode.io avatar
unknown
plain_text
23 days ago
1.3 kB
1
Indexable
Never
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Ad;

class CreateAd extends Component
{
    public $title, $description, $price, $contact_name, $phone, $email, $category_id;

    protected $rules = [
        'title' => 'required|string|max:255',
        'description' => 'required|string|max:1000',
        'price' => 'required|numeric',
        'contact_name' => 'required|string|max:255',
        'phone' => 'required|string|max:255',
        'email' => 'required|email',
        'category_id' => 'required|exists:categories,id',
    ];

    public function submit()
    {
        $this->validate();

        Ad::create([
            'title' => $this->title,
            'description' => $this->description,
            'price' => $this->price,
            'contact_name' => $this->contact_name,
            'phone' => $this->phone,
            'email' => $this->email,
            'category_id' => $this->category_id,
            'user_id' => auth()->id(),
        ]);

        session()->flash('message', 'Ad successfully created.');
        $this->reset();
    }


    public function submitForm()
    {
        session()->flash('message', 'Ad created successfully.');

        $this->reset();
    }

    public function render()
    {
        return view('livewire.create-ad');
    }
}
Leave a Comment