adrema/app/Initialize/InitializeCourses.php

29 lines
663 B
PHP
Raw Normal View History

2022-01-02 12:32:57 +01:00
<?php
2021-11-18 01:54:27 +01:00
namespace App\Initialize;
2021-11-19 22:58:27 +01:00
use App\Course\Models\Course;
2021-11-18 01:54:27 +01:00
use Aweos\Agnoster\Progress\Progress;
use Zoomyboy\LaravelNami\Api;
use Zoomyboy\LaravelNami\NamiUser;
class InitializeCourses {
private Api $api;
2022-01-02 12:32:57 +01:00
private Progress $bar;
2021-11-18 01:54:27 +01:00
public function __construct(Progress $bar, Api $api) {
$this->bar = $bar;
$this->api = $api;
}
public function handle(NamiUser $user): void
{
2022-01-02 12:32:57 +01:00
$this->bar->task('Synchronisiere Kurse', function() {
$this->api->courses()->each(function($course) {
Course::create(['nami_id' => $course->id, 'name' => $course->name]);
});
2021-11-18 01:54:27 +01:00
});
}
}