daltcore / laravel-useful-helpers
为 Laravel 框架提供的实用助手
v1.2.1
2023-08-15 08:03 UTC
README
为 Laravel 提供的实用助手
Laravel 5.3/5.4/5.5/5.6/5.7/5.8/6.0/7.0 兼容
composer require daltcore/laravel-useful-helpers dev-master
生成用户友好的密码
这样用户就不会再因为某些字符而混淆。这是视力不佳的人遇到的一个已知问题。
/** * Generate a password without i o 0 I l L etc. **/ echo user_friendly_password($length = 9, $add_dashes = false, $available_sets = 'lud');
URL 到路由名
获取给定 URL 的路由名。有时可能会很有用。
/** * In case of named routes, you can use this function to transform the uri '/' to web.home.index * @param null|string $uri = '/' * @param string $method = 'GET' **/ echo route_name(); // site.home.show echo route_name(\URL::current()); // site.home.show echo route_name('cms/user/1/delete', 'DELETE'); // cms.user.delete
检查给定的路由名是否匹配当前路由名
只需提供一个字符串,如果给定的路由名与当前路由名匹配,将返回一个布尔值。
/** * Check if the given route name is or are the same as the current route * * @param string $route * @return boolean */ if (active_route('cms.post.*')) { ...
检查给定的 URI 是否匹配当前 URI
你有两种选择
- 检查给定的 URI 是否只匹配当前 URI 的一部分
- 检查给定的 URI 是否与当前 URI 完全匹配
/** * Check if the current uri contains the given uri * * @param string $uri * @param boolean $strict * @return boolean */ if (activeUri('posts')) { ... if (activeUri('posts', true)) { ...