-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEditCompanyModal.php
71 lines (60 loc) · 2.02 KB
/
EditCompanyModal.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace App\Livewire\Company;
use App\Jobs\NotifyCompanyRoles;
use App\Livewire\Forms\CompanyForm;
use App\Mail\CompanyUpdatedMailable;
use App\Models\Company;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Validate;
use Livewire\Component;
use LivewireUI\Modal\ModalComponent;
class EditCompanyModal extends ModalComponent
{
public Company $company;
public CompanyForm $form;
/**
* Triggered on initializing of the component
* @param Company $company
* @return void
*/
public function mount(Company $company)
{
$this->company = $company;
$this->form->setCompany($company);
}
/**
* Saves the updates made on the company as redirects
* @return Application|\Illuminate\Foundation\Application|RedirectResponse|Redirector
*/
public function save()
{
$this->authorize('update', $this->company);
$this->validate();
$this->form->update();
if (Auth::user()->id == $this->company->representative->id) {
if (!$this->company->isSameCompany($this->form->company)) {
NotifyCompanyRoles::dispatch('crew', $this->company, CompanyUpdatedMailable::class);
}
return redirect(route('company.details'))
->with('status', 'Company successfully updated.');
} else {
if (!$this->company->isSameCompany($this->form->company)) {
NotifyCompanyRoles::dispatch('company representative', $this->company, CompanyUpdatedMailable::class);
}
return redirect(route('moderator.companies.show', $this->company))
->with('status', 'Company successfully updated.');
}
}
/**
* Renders the component
* @return View
*/
public function render() : View
{
return view('livewire.company.edit-company-modal');
}
}