在各種公共方法都設計好,軟件安裝成功的條件下
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
例子二:
web.php中路由為
Route::any('/test/show','UserController@show');
Controllers/UserController.php中代碼為

<?php /** * Created by PhpStorm. * User: liuyanjie * Date: 2018/12/9 * Time: 11:48 */ namespace App\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\Http\Request; class UserController extends Controller { public function show(Request $request) { $username=$request->get('username'); return $username; } }
訪問http://localhost/laravel57/public/index.php//test/show?username=aaa
便可得到如下結果
例子三:
web.php中路由為

Route::any('/test/hello',function (){ return 'This is a request from any HTTP verb'; });
然后訪問http://localhost/laravel57/public/index.php//test/hello
便可得到
例子四:
web.php中路由為
Route::any('/test/show','UserController@show');
Controllers/UserController.php中代碼為

<?php /** * Created by PhpStorm. * User: liuyanjie * Date: 2018/12/9 * Time: 11:48 */ namespace App\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\Http\Request; class UserController extends Controller { public function show(Request $request) { $username=$request->get('username'); return view('index')->with(['info'=>$username]); } }
view('index')指向 resources/views/index.blade.php ,向該文件傳遞 $info這個參數
index.blade.php 中的代碼為:
{{ $info }}
這樣便可以將參數進行顯示。
訪問http://localhost/laravel57/public/index.php//test/show?username=aaa
可得到
例子五:訪問數據庫
路由
Route::any('/test/show','UserController@show');
控制器:

<?php /** * Created by PhpStorm. * User: liuyanjie * Date: 2018/12/9 * Time: 11:48 */ namespace App\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class UserController extends Controller { public function show(Request $request) { // $username=$request->get('username'); $info=DB::table('admin')->get(); return json_encode(['code'=>'10200','message'=>'cg','data'=>$info[0]]); } }