@@ -15,33 +15,33 @@ |
||
15 | 15 | |
16 | 16 | class CreateSchedulesTable extends Migration |
17 | 17 | { |
18 | - /** |
|
19 | - * Run the migrations. |
|
20 | - * |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function up() |
|
24 | - { |
|
25 | - Schema::create(Config::get('scheduler.schedules_table'), function (Blueprint $table) { |
|
26 | - $table->increments('id'); |
|
27 | - $table->string('model_type'); |
|
28 | - $table->integer('model_id'); |
|
29 | - $table->timestamp('start_at'); |
|
30 | - $table->timestamp('end_at')->nullable(); |
|
31 | - $table->integer('status')->nullable(); |
|
32 | - $table->json('data')->nullable(); |
|
33 | - $table->timestamps(); |
|
34 | - $table->softDeletes(); |
|
35 | - }); |
|
36 | - } |
|
18 | + /** |
|
19 | + * Run the migrations. |
|
20 | + * |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function up() |
|
24 | + { |
|
25 | + Schema::create(Config::get('scheduler.schedules_table'), function (Blueprint $table) { |
|
26 | + $table->increments('id'); |
|
27 | + $table->string('model_type'); |
|
28 | + $table->integer('model_id'); |
|
29 | + $table->timestamp('start_at'); |
|
30 | + $table->timestamp('end_at')->nullable(); |
|
31 | + $table->integer('status')->nullable(); |
|
32 | + $table->json('data')->nullable(); |
|
33 | + $table->timestamps(); |
|
34 | + $table->softDeletes(); |
|
35 | + }); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Reverse the migrations. |
|
40 | - * |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public function down() |
|
44 | - { |
|
45 | - Schema::drop(Config::get('scheduler.schedules_table')); |
|
46 | - } |
|
38 | + /** |
|
39 | + * Reverse the migrations. |
|
40 | + * |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public function down() |
|
44 | + { |
|
45 | + Schema::drop(Config::get('scheduler.schedules_table')); |
|
46 | + } |
|
47 | 47 | } |
48 | 48 | \ No newline at end of file |
@@ -19,76 +19,76 @@ |
||
19 | 19 | */ |
20 | 20 | class Schedule extends Model |
21 | 21 | { |
22 | - use SoftDeletes; |
|
22 | + use SoftDeletes; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Os atributos que devem ser mutados para os tipos nátivos. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $casts = [ |
|
30 | - 'data' => 'array', |
|
31 | - ]; |
|
24 | + /** |
|
25 | + * Os atributos que devem ser mutados para os tipos nátivos. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $casts = [ |
|
30 | + 'data' => 'array', |
|
31 | + ]; |
|
32 | 32 | |
33 | 33 | /** |
34 | - * Os atributos que podem ser atribuíveis em massa. |
|
35 | - * |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $fillable = [ |
|
39 | - 'model_type', 'model_id', 'start_at', 'end_at', 'status', 'data' |
|
40 | - ]; |
|
34 | + * Os atributos que podem ser atribuíveis em massa. |
|
35 | + * |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $fillable = [ |
|
39 | + 'model_type', 'model_id', 'start_at', 'end_at', 'status', 'data' |
|
40 | + ]; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Os atributos que devem ser transformados para data. |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $dates = [ |
|
48 | - 'start_at', 'end_at', 'deleted_at' |
|
49 | - ]; |
|
42 | + /** |
|
43 | + * Os atributos que devem ser transformados para data. |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $dates = [ |
|
48 | + 'start_at', 'end_at', 'deleted_at' |
|
49 | + ]; |
|
50 | 50 | |
51 | - /** |
|
52 | - * Seta um status para o horário agendado. |
|
53 | - * |
|
54 | - * @param int|string $status Pode ser passado o ID do status ou seu nome para seta-lo no horário. |
|
55 | - */ |
|
56 | - public function setStatus($name) |
|
57 | - { |
|
58 | - $this->fill($this->parseStatusKey($name))->save(); |
|
59 | - } |
|
51 | + /** |
|
52 | + * Seta um status para o horário agendado. |
|
53 | + * |
|
54 | + * @param int|string $status Pode ser passado o ID do status ou seu nome para seta-lo no horário. |
|
55 | + */ |
|
56 | + public function setStatus($name) |
|
57 | + { |
|
58 | + $this->fill($this->parseStatusKey($name))->save(); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Retorna o ID do status caso passem o nome do status. |
|
63 | - * |
|
64 | - * @param int|string $status ID ou o nome do status. |
|
65 | - * @return array |
|
66 | - * |
|
67 | - * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
|
68 | - */ |
|
69 | - public function parseStatusKey($status) |
|
70 | - { |
|
71 | - if(is_int($status)) |
|
72 | - $status = ScheduleStatus::find($status); |
|
61 | + /** |
|
62 | + * Retorna o ID do status caso passem o nome do status. |
|
63 | + * |
|
64 | + * @param int|string $status ID ou o nome do status. |
|
65 | + * @return array |
|
66 | + * |
|
67 | + * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
|
68 | + */ |
|
69 | + public function parseStatusKey($status) |
|
70 | + { |
|
71 | + if(is_int($status)) |
|
72 | + $status = ScheduleStatus::find($status); |
|
73 | 73 | |
74 | - if(is_string($status)) |
|
75 | - $status = ScheduleStatus::where('name', $status)->first(); |
|
74 | + if(is_string($status)) |
|
75 | + $status = ScheduleStatus::where('name', $status)->first(); |
|
76 | 76 | |
77 | - if(is_null($status)) |
|
78 | - throw (new ModelNotFound)->setValues(ScheduleStatus::class); |
|
77 | + if(is_null($status)) |
|
78 | + throw (new ModelNotFound)->setValues(ScheduleStatus::class); |
|
79 | 79 | |
80 | - return ['status' => $status->id]; |
|
81 | - } |
|
80 | + return ['status' => $status->id]; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Escopo de uma consulta que busca horarios pela data de início. |
|
85 | - * |
|
86 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
87 | - * @param \Carbon\Carbon|string $start_at |
|
88 | - * @return \Illuminate\Database\Eloquent\Builder |
|
89 | - */ |
|
90 | - public function scopeByStartAt($query, $start_at) |
|
91 | - { |
|
92 | - return $query->where('start_at', $start_at); |
|
93 | - } |
|
83 | + /** |
|
84 | + * Escopo de uma consulta que busca horarios pela data de início. |
|
85 | + * |
|
86 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
87 | + * @param \Carbon\Carbon|string $start_at |
|
88 | + * @return \Illuminate\Database\Eloquent\Builder |
|
89 | + */ |
|
90 | + public function scopeByStartAt($query, $start_at) |
|
91 | + { |
|
92 | + return $query->where('start_at', $start_at); |
|
93 | + } |
|
94 | 94 | } |
95 | 95 | \ No newline at end of file |