-
Notifications
You must be signed in to change notification settings - Fork 2
/
BoothRequest.php
73 lines (61 loc) · 1.87 KB
/
BoothRequest.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
72
73
<?php
namespace App\Livewire\Company;
use App\Models\Booth;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Illuminate\Contracts\View\Factory;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
class BoothRequest extends Component
{
public $company;
public $additionalInformation;
public $requestSent;
/**
* Initializing the component
* @param $company
* @return void
*/
public function mount($company)
{
$this->company = $company;
$this->requestSent = $this->company->booth ? true : false;
}
/**
* Render the component
* @return Factory|Application|\Illuminate\Contracts\View\View|ApplicationContract
*/
public function render()
{
return view('livewire.company.booth-request');
}
/**
* Sends a request for booth
* @return void
*/
public function requestBooth()
{
$this->validate([
'additionalInformation' => 'nullable|max:255',
]);
if (!$this->company->booth) {
Booth::create(
[
'width' => 1,
'length' => 2,
'additional_information' => is_null($this->additionalInformation)
? 'No additional demands' : $this->additionalInformation,
'company_id' => $this->company->id
]
);
Auth::user()->assignRole('booth owner');
if (Auth::user()->hasRole('pending booth owner')) {
Auth::user()->removeRole('pending booth owner');
}
$this->additionalInformation = '';
$this->requestSent = true;
$this->company->refresh();
session()->flash('success', 'The request has been sent successfully.');
}
}
}