在各种公共方法都设计好,软件安装成功的条件下
routes/web.php中路由信息如下
<?php /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/index', 'Api\BannerController@index'); //后台登录操作
app/Http/ontollers/Api/BannerController.php中代码如下
<?php namespace App\Http\Controllers\Api; use Illuminate\Http\Request; use App\Http\Controllers\ApiController; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Session; use Validator; class BannerController extends ApiController { public function index(Request $request){ $validator=Validator::make($request->all(),[ 'token'=>'required|string', 'type'=>'required|int' ],[ 'token.required'=>'token为空', 'type.required'=>'type为空', 'type.int'=>'type字段仅支持整形' ] ); if($validator->fails()){ return returnJson('400','sb',$validator->errors()); } $info=DB::table('admin')->get(); return json_encode(['code'=>'10200','message'=>'cg','data'=>$info[0]]); } }
网址:http://localhost/ay/public/index.php/index?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MX0.eR3VWi_o8n_dMcrzcy3nIEeQ2Rk96hX0O8UjW33JQPM&type=1