作者:南丞 时间:2017-11-17 08:03
闲话不多说,直接起飞:
composer create-project --prefer-dist laravel/laravel laravel-erp
php artisan down 开启
php artisan up 关闭
什么是php的路由机制 1、路由机制就是把某一个特定形式的URL结构中提炼出来系统对应的参数。举个例子,如:http://main.test.com/article/1 其中:/article/1 到 m=article&id=1。 2、然后将拥有对应参数的URL转换成特定形式的URL结构,是上面的过程的逆向过程。 总体来说就是:获取路径信息->处理路径信息
Laravel路由 简单写法
Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);
Route::match(['get', 'post'], '/', function () {
//
});
Route::any('foo', function () {
//
});
Route::get('foo/{id}',function($id){
})
Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) {
//
});
Route::get('user/{name?}', function ($name = null) {
return $name;
});
//局部约束
Route::get('/{id}',function($id){
})->where('id','[0-9]+');
//全局约束
在RouteServiceProvider 中 boot方法的时候添加
Route::pattern('id', '[0-9]');
// 分组
Route::group(['prefix'=>'admin','namespace'=>'admin','middleware'=>'auth'],function(){
Route::get('/','IndexController@index');
});
// 路由文件分开写 RouteServiceProvider 中只需要加载 路由文件即可
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/system.php'));
}