public static function sendEmail() { $lowerBound = Setting::where('name', 'email_period_lower_bound')->first()->setting; $upperBound = Setting::where('name', 'email_period_upper_bound')->first()->setting; $currentHour = (int) date('H'); $email = Setting::where('name', 'email')->first()->setting; $name = Setting::where('name', 'name')->first()->setting; $lastEmail = Setting::where('name', 'last_email')->first(); $lastEmail->setting = time(); $lastEmail->save(); $lastNumber = Depression::orderBy('created_at', "DESC")->first()->id; // Encrypt yes and no so people can't accidentally trigger a choice $yes = Crypt::encrypt("yes"); $no = Crypt::encrypt("no"); if ($currentHour <= $lowerBound && $currentHour >= $upperBound) { // Do not send emails unless they're outside the set bounds $baseUrl = URL::to('/'); Mail::send('emails.reminder', ["yes" => $yes, "no" => $no, 'baseUrl' => $baseUrl], function ($m) use($email, $name, $lastNumber) { $m->from(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME')); $m->to($email, $name)->subject('Are You Depressed? (' . ($lastNumber + 1) . ')'); }); } }
</div> <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/js/materialize.min.js"></script> <script type="text/javascript" src="{{ URL::to('/') }}/js/app.js"></script> @yield('extra-js') <script type="text/javascript"> <?php $depressionStatus = !isset($depressionStatus) ? \App\Depression::orderBy('created_at', "DESC")->first()->is_depressed == 'yes' : $depressionStatus; ?> $(document).ready(function(){ @if( ($depressionStatus == 'yes') ) particlesJS.load('particles-js', 'sluggish.json', function() {}); @else particlesJS.load('particles-js', 'energetic.json', function() {}); @endif }); </script> </body> </html>
<?php /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', 'DepressionController@areTheyDepressed'); Route::get('/admin', ['as' => 'admin', 'uses' => 'DepressionController@adminForm']); Route::post('/admin/post', ['as' => 'handleAdmin', 'uses' => 'DepressionController@handleAdmin']); Route::get('/password', ['as' => 'password', 'uses' => 'DepressionController@setPassword']); Route::get('/answer/{choice}', ['as' => 'answer', 'uses' => 'DepressionController@handleEmail']); Route::group(['prefix' => 'stats'], function () { Route::get('/', 'StatsController@mainStats'); }); Route::get('/json', function () { return response()->json(\App\Depression::orderBy('created_at', "DESC")->first()); }); Route::get('/json/all', function () { return response()->json(\App\Depression::orderBy('created_at', "DESC")->get()); }); Route::get('/yes', ['as' => 'yes', 'uses' => 'DepressionController@viewYes']); Route::get('/no', ['as' => 'no', 'uses' => 'DepressionController@viewNo']);