最近公司项目用到laravel框架,一些使用上的功能,会随着自己遇到的问题,逐步完善
在routes文件夹下添加路由文件,我的是用于写app接口的,比较懒,直接起名app.php
新增之后要进行配置文件,找到app/Providers/RouteServiceProvider.php文件,新增如下
protected function mapAppRoutes()
{
Route::prefix('app')
->middleware('app')
->namespace($this->namespace.'\App')
->group(base_path('routes/app.php'));
}
然后找到map方法,添加这句 $this->mapAppRoutes();
在/app/Http/Kernel.php中添加App类名及其路径
‘app’ => \App\Http\Middleware\VerifyApp::class
在/app/Http/Middleware/文件夹下创建VerifyApp.php,并写入验证代码
class VerifyApp
{
public function handle($request, Closure $next)
{
// if (“判断条件”) {
return
n
e
x
t
(
next(
next(request);
// }
// 返回跳转到网站首页
// return redirect('/');
}
}
这样就可以在你所写定义的路由了
我的文件放在了app/Http/Controllers/App里面了
新建文件UserController.php,如图
文件里面新添加了这些方法
那么在app.php路由里面就可以定义了,想写多少就写多少吧
Route::any('login', 'UserController@login');
Route::any('register', 'UserController@register');
Route::any('sendSms', 'UserController@sendSms');
Route::any('check_mobile', 'UserController@checkMobile');