What is it that you are trying to do here?
Jan 12, 2022
29
Level 5
Cron doens't work with blade.php file
Cron doesn't output anything with this code:
php -f /home/ceercle/ceercle/resources/views/cron.blade.php
cron.blade.php file:
<?php
use Illuminate\Support\Facades\DB;
$votes = DB::table('votes')
->selectRaw("website_id, SUM(stars) AS website_rating_sum")
->groupBy('website_id')
->orderByDesc('website_rating_sum')
->get();
$i = 0;
?>
@foreach($votes as $vote)
<?php
$i++;
?>
<?php
$getWebsiteName = DB::table('sites')
->select('id', 'website_name')
->where('id', $vote->website_id)
->first();
?>
<?php
$checkIfWebsiteExistsInDB = DB::table('classement')
->where('website_name', $getWebsiteName->website_name)
->first();
if(!isset($checkIfWebsiteExistsInDB))
{
DB::table('classement')->insert([
'website_name' => $getWebsiteName->website_name,
'rank' => $i
]);
}
else
{
}
?>
Redirecting...
<script>window.location = "/site?websitename={{ $getWebsiteName->website_name }}";</script>
@endforeach
I guess 'DB' (the laravel SQL queries) are not recognized and I should for usual SQL. Is there a way to keep the laravel file and make a cron on it?
Level 102
Ok seems a fix was released before I tested https://github.com/laravel/framework/pull/40304
Update again and it should work
Please or to participate in this conversation.