<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/13
 * Time: 9:53
 */
namespace Modules\Base\Services;

use Modules\Base\Entities\File;
use Modules\Base\Entities\User;

class UserService extends BaseService
{
    public function __construct(User $user)
    {
        $this->model = $user;
    }

    public function update($id, $data)
    {
        if (isset($data['file_id'])) {
            $file = File::find($data['file_id']);
            $file && ($data['avatar'] = $file['path']);
        }

        if (isset($data['password'])) {
            $data['password'] = \Hash::make($data['password']);
        }

        if (isset($data['ext'])) {
            $old = auth()->user()->ext;
            $data['ext'] = array_merge($old, $data['ext']);
        }

        return parent::update($id, $data);
    }
}
