1 | <?php |
||
2 | |||
3 | namespace DavideCasiraghi\LaravelEventsCalendar\Models; |
||
4 | |||
5 | use DavideCasiraghi\LaravelEventsCalendar\Facades\LaravelEventsCalendar; |
||
6 | use Illuminate\Database\Eloquent\Model; |
||
7 | use Illuminate\Support\Str; |
||
8 | |||
9 | class Organizer extends Model |
||
10 | { |
||
11 | /***************************************************************************/ |
||
12 | /** |
||
13 | * The table associated with the model. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $table = 'organizers'; |
||
18 | |||
19 | /***************************************************************************/ |
||
20 | |||
21 | protected $fillable = [ |
||
22 | 'name', 'description', 'website', 'created_by', 'slug', 'email', 'phone', |
||
23 | ]; |
||
24 | |||
25 | /***************************************************************************/ |
||
26 | |||
27 | /** |
||
28 | * Get the user that owns the event. eg. $this->user. |
||
29 | */ |
||
30 | 1 | public function user() |
|
31 | { |
||
32 | 1 | return $this->belongsTo('\Illuminate\Foundation\Auth\User', 'created_by'); |
|
33 | } |
||
34 | |||
35 | /***************************************************************************/ |
||
36 | |||
37 | /** |
||
38 | * Prepare the record to be saved on DB. |
||
39 | * @param array $requestArray |
||
40 | * @param \Illuminate\Http\UploadedFile $profilePicture |
||
41 | * @return void |
||
42 | */ |
||
43 | 4 | public function preSave(array $requestArray, $profilePicture): void |
|
44 | { |
||
45 | 4 | $this->name = $requestArray['name']; |
|
46 | 4 | $this->description = clean($requestArray['description']); |
|
47 | 4 | $this->website = $requestArray['website'] ?? null; |
|
48 | 4 | $this->email = $requestArray['email'] ?? null; |
|
49 | 4 | $this->phone = $requestArray['phone'] ?? null; |
|
50 | |||
51 | // Organizer profile picture upload |
||
52 | 4 | if (! empty($profilePicture)) { |
|
53 | $imageFile = $profilePicture; |
||
54 | $imageName = $imageFile->hashName(); |
||
55 | $imageSubdir = 'organizers_profile'; |
||
56 | $imageWidth = 968; |
||
57 | $thumbWidth = 300; |
||
58 | |||
59 | LaravelEventsCalendar::uploadImageOnServer($imageFile, $imageName, $imageSubdir, $imageWidth, $thumbWidth); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
60 | $this->profile_picture = $imageName; |
||
61 | } else { |
||
62 | 4 | if (array_key_exists('profile_picture', $requestArray)) { |
|
63 | $this->profile_picture = $requestArray['profile_picture']; |
||
64 | } |
||
65 | } |
||
66 | |||
67 | //$this->created_by = Auth::id(); |
||
68 | 4 | $this->created_by = $requestArray['created_by'] ?? null; |
|
69 | 4 | if (! $this->slug) { |
|
70 | 3 | $this->slug = Str::slug($this->name, '-').'-'.rand(10000, 100000); |
|
71 | } |
||
72 | 4 | } |
|
73 | } |
||
74 |