///////////////////////////////////////资源路由

///////////////////////////////////////资源控制器

<?php

namespace App\Http\Controllers;

use App\models\testloginModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class testController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{

}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
$param = $request->all();
// var_dump($parm);
//进行验证
$validata = Validator::make($param, [
'name' => 'required',
'password' => 'required',
'img' => 'required|image'
], [
'name.required' => '用户名不可以为空',
'password.required' => '用户密码不可以为空',
'img.required' => '用户照片不可以为空',
'img.image' => '用户照片必须是JPG png类型',
]);
//如果验证失败,返回三要素并将错误信息显示出来
//将验证器的首个错误信息要获取出来
if ($validata->fails()) {
//获取指定字段的第一条错误信息,可以使用first方法:
$errors = $validata->errors()->first();
//接口三要素
$arr['status']=500;
$arr['info']=$errors;
$arr['data']='';
return response()->json($arr);
//接口主要作用:为移动端(客户端)提供数据支持(查询)
//接口给返回的数据都采用json格式
echo json_encode($arr);
}

//进行图片的处理,先将图片进行储存
$path = $request->img->store('imgs');
//将图片的前缀进行处理加入 "/"
$param['img'] = '/' . $path;
//调用模型进行添加
$res = testloginModel::index($param);
// var_dump($res);
//进行接口三要素的
if ($res) {
$arr['status'] = 200;
$arr['info'] = '添加成功';
$arr['data'] = '';
echo json_encode($arr);
} else {
$arr['status'] = 500;
$arr['info'] = '添加失败';
$arr['data'] ='';
echo json_encode($arr);
}

}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
//////////////////////////模型
use Illuminate\Database\Eloquent\Model;

class testloginModel extends Model
{
protected $table='testlogin';
public $PrimaryKey='id';
public $timestamps=false;
public static function index($param){
$obj=new self();
$obj->name=$param['name'];
$obj->password=$param['password'];
$obj->img=$param['img'];
return $obj->save();

}

////////////////////////////////////////////////////////接口文档



最新文章

  1. GOOD MEETINGS CREATE SHARED UNDERSTANDING, NOT BRDS!
  2. jQuery自动补全
  3. sql 执行动态语句
  4. Jenkins进阶系列之——07更改Jenkins的主目录
  5. Object C学习笔记17-动态判断和选择器
  6. 原 Linux搭建SVN 服务器
  7. C,C++,JAVA char,各占字节数
  8. 2015必须推荐的Android框架,猿必读系列!
  9. web2py官方文档翻译01
  10. Python自学笔记-map和reduce函数(来自廖雪峰的官网Python3)
  11. C#爬虫----Fiddler 插件开发 自动生成代码
  12. Linux虚拟机安装应用程序提示Graphical installers are not supported by the vm
  13. Python+Selenium学习--下拉框处理
  14. CuratorFramework使用
  15. linux内核完全剖析——基于0.12内核-笔记(2)-统一编址和独立编址
  16. 使用HTTPS与SSL来保证安全性
  17. connect-proxy rpm文件的安装
  18. SqlServer 获取汉字的拼音首字母
  19. 一些必看的jQuery导航插件和教程
  20. JVM垃圾收集算法的选择

热门文章

  1. 「CTSC2006」歌唱王国
  2. Swift字符串的介绍
  3. Mysql Json函数创建 (二)
  4. shell脚本一键部署——Redis(直接复制执行)亲测100% 有效
  5. TCP的报文详细解读
  6. 1Appium Desktop 的简单应用
  7. Lesson11——NumPy 位运算
  8. Redis 源码简洁剖析 12 - 一条命令的处理过程
  9. WMI简介和Event驻留
  10. shell脚本部署redis以及redis主从复制和redis-cluster集群