|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Models\Movies; |
|
6
|
|
|
use Carbon\Carbon; |
|
7
|
|
|
use Illuminate\Console\Command; |
|
8
|
|
|
use Illuminate\Support\Facades\Mail; |
|
9
|
|
|
|
|
10
|
|
|
class LastMovies extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* The name and signature of the console command. |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $signature = 'movies:newsletter'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The console command description. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $description = 'Send an email for suscribers to last movies this last month'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Create a new command instance. |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct() |
|
32
|
|
|
{ |
|
33
|
|
|
parent::__construct(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Execute the console command. |
|
38
|
|
|
* |
|
39
|
|
|
* @return mixed |
|
40
|
|
|
*/ |
|
41
|
|
|
public function handle() |
|
42
|
|
|
{ |
|
43
|
|
|
/* |
|
44
|
|
|
* php5-cli php5-common php5-curl php5-gd |
|
45
|
|
|
* php5-imap php5-intl php5-json php5-mcrypt php5-mysql php5-pspell |
|
46
|
|
|
* php5-readline php5-sqlite |
|
47
|
|
|
*/ |
|
48
|
|
|
|
|
49
|
|
|
// SQL query |
|
50
|
|
|
$results = Movies::where('date_release','>=', new Carbon('-1 month')) |
|
51
|
|
|
->where('date_release','<=', new Carbon('now')) |
|
52
|
|
|
->get(); |
|
53
|
|
|
|
|
54
|
|
|
// je parcours mes films |
|
55
|
|
|
foreach($results as $movie){ |
|
56
|
|
|
|
|
57
|
|
|
dump($movie->id); |
|
58
|
|
|
$users = $movie->actors(); |
|
|
|
|
|
|
59
|
|
|
exit(dump(($movie->actors()))); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
// je parcours les favoris(user) de chaque film |
|
62
|
|
|
foreach($users as $user){ |
|
|
|
|
|
|
63
|
|
|
dump($user); |
|
64
|
|
|
exit('stop'); |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
exit('TOP'); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
//send an email |
|
72
|
|
|
Mail::send('Emails/newsletter', [], function ($m) { |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
$m->from('[email protected]', 'Florent Boyer'); |
|
75
|
|
|
$m->to("[email protected]", "Boyer Julien") |
|
76
|
|
|
->subject('Welcome to newsletter'); |
|
77
|
|
|
}); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.