flostone / larahelpers
Requires
- php: >=5.4.0
- illuminate/http: ~5.0
- illuminate/session: ~5.0
- illuminate/support: ~5.0
This package is not auto-updated.
Last update: 2020-09-05 07:01:11 UTC
README
为Laravel 5提供一些自定义辅助函数和函数
##安装
在composer中要求该包
composer require flo5581/larahelpers dev-master
在app.php中注册服务提供者
'Flo5581\Larahelpers\BladeExtensions'
##功能
####Laravel函数和定义
controller()
-> 类似于 Route::controller()
controllers()
-> 类似于 Route::controllers()
get_routes()
-> 在数组中注册多个GET路由,
例如:get_routes(['/' => function(){return view('index');}, 'test' => 'TestController@index']);
post_routes()
-> 与 get_routes()
相同,但用于POST请求
group()
-> 类似于 Route::group()
input()
-> 类似于 Input::get()
,Input::all()
(如果没有设置值)
user()
-> 类似于 Auth::user()
login()
-> 类似于 Auth::login()
或 Auth::loginUsingId()
如果提供了用户模型或ID,
例如:login(['email' => $email, 'password' => $password])
,login($user)
,login(1)
logout()
-> 类似于 Auth::logout()
check()
-> 类似于 Auth::check()
####新函数和定义
days_in_month($month, $year)
-> 计算月份中的天数,接受参数1:月份(int),参数2:年份(int)
num_to_word($number)
-> 将数字转换为文字
####Blade扩展
@use(path)
-> 类似于php的use,例如:@use(App\Models\User)
@define(code)
-> 在blade中定义变量,例如:@define($i = 1)
@echo(string)
-> 输出内容,例如:@echo('hi')
@print(var)
-> 输出内容,例如:@print($array)
@dd(var)
-> 类似于 dd()
,例如:@dd($user)
@php, @endphp
-> 实际上是打开和关闭php标签,例如:@php echo 'hi'; @endphp