Jan 31, 2021
0
Level 6
Livewire single column update
I have a form that when submitted it sends an email to the customer with a link to approve. When they click on the link it will show a checkbox for approval and a submit button.
I have a "Job" class that stores the form in the database and kicks off an email. I have another class "Approve" that will display the approve form and update the "Job" approve Boolean to true.
How can I update the job form from a separate class without resubmitting all fields and just update the "approve" column similar to the "put" method?
Job Class
<?php
namespace App\Http\Livewire;
use App\Mail\WorkorderMailable;
use App\Models\Order;
use Livewire\Component;
use Ramsey\Uuid\Uuid;
use Illuminate\Support\Facades\Mail;
class Job extends Component
{
public $email;
public $item;
public function resetInputs()
{
$this->email = '';
$this->item = '';
}
protected $rules = [
'email' => 'required',
];
public function submit()
{
$this->validate();
$order = Order::create([
'uuid' => Uuid::uuid1(),
'email' => $this->email,
'item' => $this->item,
]);
\Mail::to($this->email)->send(new WorkorderMailable($order));
$this->resetInputs();
}
public function render()
{
return view('livewire.job');
}
}
Approve Class
<?php
namespace App\Http\Livewire;
use App\Models\Order;
use Livewire\Component;
class Approve extends Component
{
public $job;
public $approve;
public function mount($uuid)
{
$this->job = Order::where('uuid', $uuid)->first();
}
public function approve()
{
$data = array(
'approve' => $this->approve,
);
dd($data);
}
public function render()
{
return view('livewire.approve')
->layout('layouts.app');
}
}
Please or to participate in this conversation.