-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSponsorshipRequest.php
63 lines (56 loc) · 1.61 KB
/
SponsorshipRequest.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
<?php
namespace App\Livewire\Company;
use App\Models\Sponsorship;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Illuminate\Contracts\View\Factory;
use Illuminate\Foundation\Application;
use Illuminate\View\View;
use Livewire\Component;
class SponsorshipRequest extends Component
{
public $company;
public $tiers;
public $chosenTierName;
public $requestSent;
/**
* Triggered when initializing a component
* @param $company
* @return void
*/
public function mount($company)
{
$this->company = $company;
$this->tiers = Sponsorship::all();
foreach ($this->tiers as $tier) {
if ($tier->leftSpots() > 0) {
$this->chosenTierName = $tier->name;
break;
}
}
$this->requestSent = (bool)$this->company->sponsorship;
}
/**
* Render the component
* @return View
*/
public function render(): View
{
return view('livewire.company.sponsorship-request');
}
/**
* Sends a request for a sponsorship
* @return void
*/
public function requestSponsorship()
{
if (!$this->company->sponsorship) {
$chosenTier = $this->tiers->firstWhere('name', $this->chosenTierName);
$this->company->sponsorship_id = $chosenTier->id;
$this->company->is_sponsorship_approved = 0;
$this->company->save();
$this->company->refresh();
$this->requestSent = true;
session()->flash('success', 'The request has been sent successfully.');
}
}
}