水电费
![](https://img.haomeiwen.com/i3301559/0f14432dd2a7a061.png)
<?php
use Illuminate\Support\Facades\Input;
/*
|--------------------------------------------------------------------------
| 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.
|
*/
// 根域名下的 welcome控制器的index方法
Route::get('/','welcomeController@index');
//
//Route::get('/', function () {
// return view('welcome');
//});
//Route::get('test',function(){
// return 'get请求的test路由';
//});
//Route::post('test',function(){
// return 'post请求的test路由';
//});
//不是特别敏感的信息 可以用any
//Route::any('test',function(){
// return 'post请求的test路由';
//});
//Route::any('myhome','MyController@index');
//s9 s10 s11
Route::get('/udb',function (){
$user = new App\User;
//相当于 select * from users;
// return $user->all();
// return $user->userAll();
//
// return $user->userFind(1);
// return $user->userFindOrFail(4);
// return $user->userWhereGet();
//增1
// $user->userAdd();
//增2 :: 失败,找小伙伴们问问
// $user->userWhereGet();
// $user->userAddFromArr();
// return $user->all();
//
//单个更新
// $user->userUpdate();
//
// 批量更新
// $user->userUpdateMulti();
//
// 删除
// $user->userDelete();
// return $user->userRead();
//
// s11 集合 -- 用不同的条件选出不同的组
// 存取数据 相依赖 至少有可能取
//
// $users = $user->all(); //$users 就是一个集合 用dd方法去查看一个集合
// $userarray = $users->toArray(); //返回二维数组
// dd($users);//dd() 相当于var_dump(); and die();
// dd($userarray);
//
// $userss = $users->toArray();
// dd($userss);
// return $user->all();
// $arr = ['one','two','three'];
// $collection = collect($arr);
// dd($collection);
// return $collection->all();
// $arrkey = ['one'=>1,'two'=>2,'three'=>3,1=>'yiyiyiy'];
// $collectionkey = collect($arrkey);
//
//contains() 方法:值里边有木有 one
// $r = $collection->contains('three');
//has() 方法 :键里边有木有 ten
// $r = $collectionkey->has('1');
//take() 方法 : 取集合的一部分
// 从前面开始 取2个
// $r = $collectionkey->take(2);
// 从后往前 取2个
// $r = $collectionkey->take(-2);
// dd($r);
// return $r ? '有' : '没有';
//
// $users = $user->all();
// dd($users);
// return $users;
// return $users->toJSON();//其实是默默调用了 $users对象里的toJSON方法
});
//Route::get('{number}',function ($number){
// return view('home'.$number);
//});
//s12 请求的基础
Route::get('s12',function(){
//打印单个get请求的值 $_GET['age']
// return Input::get('age');
//post get file json 全部打印出来
return Request::all();
});
Route::get('form',function(){
return view('form');
});
Route::post('s12p',function(){
return Request::all();
});
//s13 请求实例
//1 query url后的查询部分()
//2 get默认值
//3 has
//4 exists
Route::get('s13',function (){
// return Request::query();
// return Request::query('name');
// return Request::get('name','HanMeimei');//没有的话 默认给个HanMeimei,没有给定默认值的话 也不报错,打印空
//has()键存在并且不空,真;
//exists()只检查键存在,真;键不存在,假
// dd(Request::has('name'));
dd(Request::exists('name'));
});
//s14 请求检索
//1 only 包括
//2 except 除了
//3 url http://la.co/s14
//4 fullUrl http://la.co/s14?a=aaa&b=bbb&c=ccc&d=ddd&e=eee
Route::get('s14',function (){
// return Request::only('a','b','e');
// return Request::except('a','b','e');
dd(Request::url());
dd(Request::fullUrl());
});
//s15 请求历史
// flash()
// flashOnly()
// flashExcept()
// old()
Route::get('s15',function (){
return Request::old();
});
Route::get('s15save',function (){
return Request::flash();
});
//s16 文件上传
Route::get('s16',function(){
return view('file');
});
Route::post('s16f',function(){
// return Request::all();
// dd(Request::file());
// dd(Request::file('touxiang'));
// dd(Request::file('touxiang')->getSize());
// dd(Request::file('touxiang')->getClientOriginalName());
dd(Request::file('touxiang')->getClientOriginalExtension());
// dd(Request::hasfile('touxiang'));
});
//s17 会话
Route::get('s17userindex',"UserController@index");
Route::get('s17',function (){
// Session::session()->regenerate();
// Session::put('username','333333');
// Session::save();
// dd(Session::all());//查看所有session数组
// var_dump(Session::all());
//get() 获取指定下表的session值
// return Session::get('username');
//has检测指定下标是否有
// dd(Session::has('username'));
//
//清除指定下标的session
// Session::forget('0');
//用一次就删掉 获取并删除数据
//Session::pull('name');
//session() 传数组进去,直接写
session(['name'=>'lixiaoquan']);
});
Route::any('s172',function (){
// Session::put('username','lala');
dd(Session::all());//查看所有session数组
});
Route::any('s17pull',function (){
Session::pull('name');
});
//s18 会话 从文件改为数据库
//第一步 env SESSION_DRIVER=file 改为 SESSION_DRIVER=database
//第二步 三小步
// php artisan session:table
// composer dump-autoload
// php artisan migrate
//s19&20 验证 数据验证-基础用法
Route::get('s18','GoodsController@create');
// 显示创建博客文章表单...
Route::get('post/create', 'PostController@create');
// 存储新的博客文章...
Route::post('post/store', 'PostController@store');
//s21 哈希 Hash
//make()用来加密
//check()用来检查
Route::get('s21',function (){
$password = Request::get('password');
$hashedPassword = Hash::make($password);
return $password.'<br>'.$hashedPassword;
});
Route::get('s21save',function (){
$password = Request::get('password');
$hashedPassword = Hash::make($password);
//session(['hashedPassword'=>$hashedPassword]);
//return $password.'<br>'.$hashedPassword;
dd(Session::all());
});
Route::get('s21check',function (){
$password2 = Request::get('password2');
//$hashedPassword = Hash::make($password);
//session(['hashedPassword'=>$hashedPassword]);
//return $password.'<br>'.$hashedPassword;
$password = session('hashedPassword');
if(Hash::check($password2,$password))
{
return '密码输入正确!';
} else {
return '密码输入有误!';
}
});
//s22 帮助函数 -- 数组相关
//head 返回数组中的第一个元素
//array_only 返回数组中的指定元素
//array_first 返回符合条件的第一个元素值
//array_add 返回压入元素后的新数组
//array_except 返回除了元素后的数组
//array_flatten 不管数组有多少维,将每个值作为一维数组的值返回
//array_where 用第二个函数过滤第一参数数组中的元素key或者value
//last
Route::get('s22',function (){
$arrI = ['a','b','1','5'];
$arr = [
'name'=>'Bob',
'age'=>'18',
'job'=>'phper',
];
$arrFirst = [10,11,19,25,45,46,51];
//return head($arrI); //a
//return array_only($arr,['name','age']); //{"name":"Bob","age":"18"}
//return array_first($arrFirst,function($key,$value){
// return $key > 2;
//});
//return array_add($arr,'lover','lily'); //{"name":"Bob","age":"18","job":"phper","lover":"lily"}
//return array_except($arr,'job'); //{"name":"Bob","age":"18"}
//$arrFlatten = [
// 'a'=>1,
// 'b'=>[
// 'c'=>1,
// 'd'=>1
//]
//];
//return array_flatten($arrFlatten); //[1,1,1]
//$arr_for_array_where = [
// 'name'=>'lucy',
// 'age'=>18,
// 'job'=>'javaer',
// 'phone'=>'muyouphone',
//];
//return array_where($arr_for_array_where,function ($k,$v){
// return is_string($v);
//});//{"name":"lucy","job":"javaer","phone":"muyouphone"}
return array_last($arr);
});
//s23 帮助函数 -- 路径相关
//app_path
//config_path
//public_path
//storage_path 过程文件位置
Route::get('s23',function (){
//return app_path();//D:\www\vh\laravel\52\mall\app
//return config_path();//D:\www\vh\laravel\52\mall\config
//return public_path();//D:\www\vh\laravel\52\mall\public
return storage_path();//D:\www\vh\laravel\52\mall\storage
});
//s23 帮助函数 -- 字符串相关
//str_plural 复数形式
//starts_with 第一个字符串是不是以第二个字符串开头
//ends_with 第一个字符串是不是以第二个字符串结尾
//camel_case 小驼峰
//class_basename 取类名
//str_limit 指定位数后补...
//str_is 后边字符是否匹配前面的模式
Route::get('s24',function (){
//return str_plural('cup');
//return str_plural('thief');
//return str_plural('woman');
//return str_plural('wife');
//return str_plural('apple');
//dd(starts_with('abcde','aab'));
//dd(ends_with('abcde','e'));
//dd(camel_case('hello_world'));//helloWorld
//dd(class_basename('Illuminate\Http\Request'));//Request
//dd(str_limit('abcde',3));
//后边字符是否匹配前面的模式
dd(str_is('ab*','abcd'));
});
网友评论