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
|
|
|
public function user() |
31
|
|
|
{ |
32
|
|
|
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
|
3 |
|
public function preSave(array $requestArray, $profilePicture): void |
44
|
|
|
{ |
45
|
3 |
|
$this->name = $requestArray['name']; |
46
|
3 |
|
$this->description = clean($requestArray['description']); |
47
|
3 |
|
$this->website = $requestArray['website']; |
48
|
3 |
|
$this->email = $requestArray['email']; |
49
|
3 |
|
$this->phone = $requestArray['phone']; |
50
|
|
|
|
51
|
|
|
// Organizer profile picture upload |
52
|
3 |
|
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); |
|
|
|
|
60
|
|
|
$this->profile_picture = $imageName; |
61
|
|
|
} else { |
62
|
3 |
|
if (array_key_exists("profile_picture",$requestArray)){ |
63
|
|
|
$this->profile_picture = $requestArray['profile_picture']; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
//$this->created_by = Auth::id(); |
68
|
3 |
|
$this->created_by = $requestArray['created_by']; |
69
|
3 |
|
if (! $this->slug) { |
70
|
2 |
|
$this->slug = Str::slug($this->name, '-').'-'.rand(10000, 100000); |
71
|
|
|
} |
72
|
3 |
|
} |
73
|
|
|
} |
74
|
|
|
|