水電費
Paste_Image.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'));
});