adrema/app/Initialize/InitializeCourses.php

30 lines
522 B
PHP
Raw Permalink 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;
2022-09-02 00:45:39 +02:00
use DB;
2021-11-18 01:54:27 +01:00
use Zoomyboy\LaravelNami\Api;
2022-03-11 20:19:17 +01:00
class InitializeCourses
{
2021-11-18 01:54:27 +01:00
private Api $api;
2022-03-11 20:19:17 +01:00
public function __construct(Api $api)
{
2021-11-18 01:54:27 +01:00
$this->api = $api;
}
2022-02-19 18:06:07 +01:00
public function handle(): void
2021-11-18 01:54:27 +01:00
{
2022-03-11 20:19:17 +01:00
$this->api->courses()->each(function ($course) {
2022-01-03 01:17:24 +01:00
Course::create(['nami_id' => $course->id, 'name' => $course->name]);
2021-11-18 01:54:27 +01:00
});
}
2022-09-02 00:45:39 +02:00
public function restore(): void
{
DB::table('courses')->delete();
}
2021-11-18 01:54:27 +01:00
}