laravel之路由设置

代码如下:

访问就是:

代码附上:

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/ Route::get('/', function () {
return view('welcome');
});
//基本路由 Route::get('basic',function(){ return 'basic';
}); Route::post('basic1',function(){ return 'basic1';
});
//多请求路由,响应指定的路由
Route::match(['get','post'],'multy',function(){
return 'multy';
});
//响应所有的路由
Route::any('multy1',function(){
return 'multy1';
}); //响应参数
Route::get('user/{id}',function($id){
return $id;
});
//路由参数使用默认值
Route::get('user1/{name?}',function($name=null)
{
return $name;
});
//把name使用正则进行匹配
Route::get('user2/{name?}',function($name=null)
{
return $name;
})->where('name','[A-Za-z]+');
//路由使用多个参数
Route::get('user3/{id}/{name?}',function($id,$name)
{
return $id.'=>'.$name;
})->where(['id'=>'[0-9]+','name'=>'[A-Za-z]+']);
//路由别名
Route::get('user/center',['as'=>'center',function(){
return Route('center');
}]);
//在路由中输出视图
Route::get('shitu',function(){
return view('welcome');
});
如有疑问:https://learnku.com/docs/laravel/5.1/routing/1041#required-parameters

laravel之路由的更多相关文章

  1. [PHP] - Laravel - Route路由

    前言 这里使用的是Laravel 5 PHP Laravel的路由比较强悍,但也正因如此,不统一而容易凌乱.比如在路由中可以直接写方法操作(破坏封装啊) 以下是个人学习的例子,不供参考 路由中的直接方 ...

  2. laravel的路由分组,中间件,命名空间,子域名,路由前缀

    laravel的路由分组,就是把一些具有相同特征的路由进行分组,比如一些路由需要进行验证,一些路由有共同的前缀,一些路由有相同的控制器命名空间等. 这样把路由组合在一起,方便管理,维护性更好. Rou ...

  3. Laravel中路由怎么写(二)

    1.路由命名——给路由起个名字 1.1 基本使用 我们使用as关键字来为路由命名: Route::get('/hello/Laravel',['as'=>'academy',function() ...

  4. laravel 配置路由 api和web定义的路由的区别详解

    1.路由经过中间件方面不同 打开kerenl.php就可以看到区别 protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware ...

  5. laravel route路由

    基本路由 您的应用程序的绝大多数路由将在 app/routes.php 文件中定义.Laravel 中最简单的路由由一个 URI 和一个闭包调用组成. 基本 GET 路由 代码如下: Route::g ...

  6. 学习laravel之路由问题 404

    今天配置路由的时候,只有原来的自带路由可用: Route::get('/', function(){    return View::make('hello');}); 再网上搜索了办法:来自:htt ...

  7. [Laravel]配置路由小记

    Laravel:4.2 使用的后台是:laravel-backend php artisan routes 使用这个代码,可以看到显示目前项目的路由器 ,我需要添加功能,我就需要添加路由 /* |-- ...

  8. laravel route路由,视图和response和filter

    Laravel充分利用PHP 5.3的特性,使路由变得简单并富于表达性.这使得从构建API到完整的web应用都变得尽可能容易.路由的实现代码在 application/routes.php 文件. 和 ...

  9. 【笔记】 laravel 的路由

    路由简介 : 请求对应着路由,将用户的请求转发给相应的程序进行处理 建立URL与程序之间的映射 Laravel中的请求类型:get.post.put.patch.delete   Route::get ...

随机推荐

  1. MyEclipse 2015 SVN 安装

    SVN的在线安装 1.打开MyEclipse,找到顶部菜单栏 Help(帮助)-Install from Site…(从网站安装),如下图 2. 点击Install from Site…后会出现让你选 ...

  2. YUV422 YUV420 Planar \ Semi-Planar \ Interleaved YCbCr与YUV

    YCbCr是DVD.摄像机.数字电视等消费类视频产品中,常用的色彩编码方案.YCbCr 有时会称为 YCC..Y'CbCr 在模拟分量视频(analog component video)中也常被称为 ...

  3. js-工具函数

    /** * 将文件大小转换成 ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],单位 * @param bytes * @returns */ ...

  4. zookeeper视图工具

    https://www.cnblogs.com/xd502djj/p/8919425.html

  5. 数组去重Demo引出的思考

    package com.pers.Stream; import java.util.*; import java.util.stream.Collectors; import java.util.st ...

  6. (原)tensorflow使用eager在mnist上训练的简单例子

    转载请注明出处: https://www.cnblogs.com/darkknightzh/p/9989586.html 代码网址: https://github.com/darkknightzh/t ...

  7. 物联网架构成长之路(30)-Spring Boot Admin微服务WebUI监控

    0. 前言 一个完整的微服务解决方案包含了许多微服务,基于我们需要观察各个微服务的运行状态,因此Spring Boot 生态提供了Spring Boot Admin 这个组件来实现微服务管理WEB U ...

  8. 如何保持github的fork于主干同步

    step1: https://help.github.com/articles/configuring-a-remote-for-a-fork/ step2: https://help.github. ...

  9. Control group namespaces

    https://www.toptal.com/linux/separation-anxiety-isolating-your-system-with-linux-namespaces https:// ...

  10. centos6 利用外部的smpt服务器计划任务发送邮件

    centos可通过修改配置文件以使用外部SMTP服务器,达到不使用sendmail而用外部的smtp服务器发送邮件的目的, 操作如下: 一.安装mailx与sendmail # yum -y inst ...