1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace App\Repositories\Models\User;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Models\Base\Admin;
- use App\Repositories\Models\Model;
- 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()
- {
- 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();
- });
- }
- }
|