7 changed files with 110 additions and 48 deletions
@ -0,0 +1,56 @@ |
|||
<?php |
|||
|
|||
namespace App\Jobs; |
|||
|
|||
use Illuminate\Bus\Queueable; |
|||
use Illuminate\Contracts\Queue\ShouldBeUnique; |
|||
use Illuminate\Contracts\Queue\ShouldQueue; |
|||
use Illuminate\Foundation\Bus\Dispatchable; |
|||
use Illuminate\Queue\InteractsWithQueue; |
|||
use Illuminate\Queue\SerializesModels; |
|||
use Illuminate\Support\Facades\Http; |
|||
use App\Models\CovidData; |
|||
use Carbon\Carbon; |
|||
|
|||
class UpdateCovidData implements ShouldQueue |
|||
{ |
|||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
|||
|
|||
/** |
|||
* Create a new job instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
// |
|||
} |
|||
|
|||
/** |
|||
* Execute the job. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function handle() |
|||
{ |
|||
$url = 'https://api.apify.com/v2/datasets/Gm6qjTgGqxkEZTkuJ/items?format=json&clean=1'; |
|||
$res = Http::get($url); |
|||
CovidData::whereNotNull('id')->delete(); |
|||
foreach ($res->collect() as $data) { |
|||
try { |
|||
$attr = []; |
|||
$attr["infected"] = $data["infected"] ?? null; |
|||
$attr["deceased"] = $data["deceased"] ?? null; |
|||
$attr["recovered"] = $data["recovered"] ?? null; |
|||
$attr["quarantined"] = $data["quarantined"] ?? null; |
|||
$attr["tested"] = $data["tested"] ?? null; |
|||
$attr["created_at"] = Carbon::createFromFormat('Y-m-d\TH:i:s+', $data["lastUpdatedAtApify"]); |
|||
$d = new CovidData($attr); |
|||
$d->save(); |
|||
} catch (\Exception $e) { |
|||
dd($data, $e); |
|||
} |
|||
}; |
|||
//dd(CovidData::all()); |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
<?php |
|||
|
|||
namespace App\Models; |
|||
|
|||
use Illuminate\Database\Eloquent\Model; |
|||
|
|||
class CovidData extends Model |
|||
{ |
|||
protected $table = 'covid_data'; |
|||
protected $fillable = ['infected','deceased','recovered','quarantined','tested','created_at']; |
|||
|
|||
public $timestamps = false; |
|||
} |
|||
@ -1,44 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Models; |
|||
|
|||
use Illuminate\Contracts\Auth\MustVerifyEmail; |
|||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|||
use Illuminate\Foundation\Auth\User as Authenticatable; |
|||
use Illuminate\Notifications\Notifiable; |
|||
use Laravel\Sanctum\HasApiTokens; |
|||
|
|||
class User extends Authenticatable |
|||
{ |
|||
use HasApiTokens, HasFactory, Notifiable; |
|||
|
|||
/** |
|||
* The attributes that are mass assignable. |
|||
* |
|||
* @var array<int, string> |
|||
*/ |
|||
protected $fillable = [ |
|||
'name', |
|||
'email', |
|||
'password', |
|||
]; |
|||
|
|||
/** |
|||
* The attributes that should be hidden for serialization. |
|||
* |
|||
* @var array<int, string> |
|||
*/ |
|||
protected $hidden = [ |
|||
'password', |
|||
'remember_token', |
|||
]; |
|||
|
|||
/** |
|||
* The attributes that should be cast. |
|||
* |
|||
* @var array<string, string> |
|||
*/ |
|||
protected $casts = [ |
|||
'email_verified_at' => 'datetime', |
|||
]; |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
<?php |
|||
|
|||
use Illuminate\Database\Migrations\Migration; |
|||
use Illuminate\Database\Schema\Blueprint; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
class CreateCovidDataTable extends Migration |
|||
{ |
|||
/** |
|||
* Run the migrations. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function up() |
|||
{ |
|||
Schema::create('covid_data', function (Blueprint $table) { |
|||
$table->id(); |
|||
$table->integer('infected')->nullable(); |
|||
$table->integer('deceased')->nullable(); |
|||
$table->integer('recovered')->nullable(); |
|||
$table->integer('quarantined')->nullable(); |
|||
$table->integer('tested')->nullable(); |
|||
$table->dateTime('created_at'); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Reverse the migrations. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function down() |
|||
{ |
|||
Schema::dropIfExists('covid_data'); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue