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