现在好了,我删掉重新复制了一遍,就好了,不知道什么情况,可能是缓存
<?php
/**
* Created by PhpStorm.
* User: zhoujie
* Date: 16/10/30
* Time: 下午11:03
*/
namespace App\Http\Controllers\Test;
use App\Http\Controllers\BaseController;
use App\Models\Test;
class TestUpdateController extends BaseController
{
public function __construct()
{
parent::__construct();
}
public function create()
{
$param = $this->validate_process();
$id = Test::insertGetId($param);
reset($param); $param['id'] = $id;
return $id ? response()->json($param) : $this->errorOutput('CREATE_FAILD');
}
public function update()
{
$this->validation(['id' => 'required|numeric'], ['id' => '测试id']);
$param = $this->validate_process();
$id = intval($this->input['id']);
$res = Test::where('id', $id)->update($param);
return $res ? response()->json(['success' => 1]) : $this->errorOutput('UPDATE_FAILD');
}
public function delete()
{
$this->validation(['id' => 'required|numeric'], ['id' => '测试id']);
$id = intval($this->input['id']);
$res = Test::destroy($id);
return $res ? response()->json(['success' => 1]) : $this->errorOutput('DELETE_FAILD');
}
private function validate_process()
{
$rules = [
'name' => 'required|unique:mysql-i.users|alpha_dash|max:32',
'password' => 'required|alpha_dash|min:6|max:32',
'tel' => 'required|digits_between:3, 18',
'email' => 'required|email|min:3|max:32',
'avatar' => 'min:3'
];
$attr = [
'name' => '用户名',
'password' => '用户密码',
'tel' => '用户电话',
'email' => '用户邮箱',
'avatar' => '用户头像',
];
if (!empty($this->input['id'])) { $rules['name'] = 'required|alpha_dash|max:32'; }
$this->validation($rules, $attr);
return [
'name' => trim($this->input['name']),
'password' => trim($this->input['password']),
'tel' => trim($this->input['tel']),
'email' => trim($this->input['email']),
'avatar' => $this->input['avatar'] ? serialize($this->input['avatar']) : '',
'create_time' => TIMENOW
];
}
}