laravel 基础面试题-偏交谈-2020-12-11-主讲laravel命名路由闭包
感谢关注本人公众号: 上海 PHP 自学中心
qq群(3年2万):517085546
1. Laravel 中的路由命名是什么?
路由命名使得在生成重定向或者 URL 的时候更加方便地引用路由。您可以通过将 name 方法加到路由定义上来指定命名路由:
Route::get('user/profile', function () {
//
})->name('profile');
您可以为控制器操作指定路由名称:
Route::get('user/profile', 'UserController@showProfile')->name('profile');
为路由分配名称后,您可以在生成 URL 或重定向时,通过全局路由功能使用路由名称:
// Generating URLs...
$url = route('profile');
// Generating Redirects...
return redirect()->route('profile');
2. Laravel 中的闭包是什么?
闭包是一个匿名函数。闭包通常用作回调方法,并且可以用作函数中的参数
function handle(Closure $closure) {
$closure('Hello World!');
}
handle(function($value){
echo $value;
});
3. 列出 Laravel 中查询构建器提供的一些聚合方法?
聚合函数是一种功能,能够将多行的值组合在一起,作为某些条件下的输入,以形成具有更重要含义或度量值 (例如集合,包或列表) 的单个值。
以下是 Laravel 查询构建器提供的一些聚合方法的列表:
- count()
$products = DB::table(‘products’)->count();
- max()
$price = DB::table(‘orders’)->max(‘price’);
- min()
$price = DB::table(‘orders’)->min(‘price’);
- avg()
*$price = DB::table(‘orders’)->avg(‘price’);
- sum()
$price = DB::table(‘orders’)->sum(‘price’);
防爬虫说明
禁止 学习某地爬虫,知乎爬虫,CSDN 爬虫。
本文,首发在 learnku 社区。
@author
汪春波(www.shxdledu.cn)