123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace App\Repositories\Models\User;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Models\Base\Admin;
- use App\Repositories\Models\Model;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Support\Facades\App;
- use Illuminate\Support\Facades\Hash;
- use Prettus\Repository\Contracts\Transformable;
- use Prettus\Repository\Traits\TransformableTrait;
- /**
- * Class Student.
- *
- * @package namespace App\Repositories\Models\User;
- */
- class Student extends Model implements Transformable
- {
- use TransformableTrait;
- protected $table = 'user_students';
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $guarded = [];
- protected static function booted()
- {
- self::language();
- static::created(function (Student $student) {
- Admin::query()->create([
- 'username' => $student->account,
- 'password' => Hash::make($student->password),
- 'name' => $student->turename,
- 'headimg' => $student->headimg,
- 'type' => Student::class,
- 'type_id' => $student->id,
- 'is_admin' => 0,
- 'department_id' => 0,
- 'role_id' => 1,
- 'status' => ModelStatusEnum::OK,
- ]);
- });
- static::saved(function (Student $student) {
- $data = [
- 'username' => $student->account,
- 'name' => $student->turename,
- 'password' => Hash::make($student->password),
- 'headimg' => $student->headimg,
- ];
- Admin::query()->where('type_id', $student->id)->where('type', Student::class)->update($data);
- });
- static::deleted(function (Student $student) {
- Admin::query()->where('type_id', $student->id)->where('type', Student::class)->delete();
- });
- }
- }
|