网站首页 > 技术文章 正文
2023 年情人节当天,Laravel10 正式版发布了!
Laravel 10 通过引入参数和返回类型到所有应用程序核心方法,,延续了 Laravel 9 中所做的改进。此外,还引入了一个新的、对开发人员友好的抽象层,用于启动和与外部进程交互。另外,引入了 Laravel Penant,以提供一种管理应用程序“功能标志”的绝佳方法。
要获得有关此版本的所有细节,请查看官方 发行说明 和升级指南。下面介绍一些新版本的新特性:
方法签名 + 返回类型
<?php
namespace App\Http\Controllers;
use App\Models\Flight;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class FlightController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(): Response
{//}
/**
* Display the specified resource.
*/
public function show(Flight $flight): Response
{//}
// ...
}
此特性完全向后兼容现有应用程序。因此,没有这些类型提示的现有应用程序将继续正常运行。
Laravel Pennant
新的集成软件包 Laravel Penant 已经发布。Laravel Penant 提供了一种轻量级、简化的方法来管理应用程序的功能标志。开箱即用,Pennant 包括一个内存数组驱动程序和一个用于持久功能存储的数据库驱动程序。
该特性可以通过 Feature::define 方法轻松定义:
use Laravel\Pennant\Feature;
use Illuminate\Support\Lottery;
Feature::define('new-onboarding-flow', function () {return Lottery::odds(1, 10);
});
定义功能后,您可以轻松确定当前用户是否可以访问给定功能:
if (Feature::active('new-onboarding-flow')) {// ...}
当然,为了方便起见,Blade 指令也可用:
@feature('new-onboarding-flow')
<div>
<!-- ... -->
</div>
@endfeature
更多信息请参考详细文档介绍:comprehensive Pennant documentation.
进程交互
Laravel 10. x 引入了一个很好用的抽象层,用于通过新的 Process 方法启动外部进程并与之交互:
use Illuminate\Support\Facades\Process;
$result = Process::run('ls -la');
return $result->output();
进程甚至可以在池中启动,从而方便地执行和管理并发进程:
use Illuminate\Process\Pool;
use Illuminate\Support\Facades\Pool;
[$first, $second, $third] = Process::concurrently(function (Pool $pool) {$pool->command('cat first.txt');
$pool->command('cat second.txt');
$pool->command('cat third.txt');
});
return $first->output();
此外,为了方便测试,也可以虚拟一个进程:
Process::fake();
// ...
Process::assertRan('ls -la');
更多进程介绍详见文档:comprehensive process documentation.
Horizon / Telescope 改进
Horizon and Telescope 已经更新了一个新的,现代的外观,包括改进的排版,行间距和设计:
猜你喜欢
- 2024-09-15 laravel 使用 mongodb(laravel 使用gmail邮箱发送验证码)
- 2024-09-15 Laravel的这10个用法,你都没用过吧
- 2024-09-15 PHP Laravel框架用户权限管理,按钮级别控制(详细)
- 2024-09-15 3分钟短文:太爽了,用Laravel写API接口
- 2024-09-15 Laravel5.8简明教程(laravel-admin)
- 2024-09-15 3分钟短文:Laravel请求对象方法极多,可不是花拳绣腿
- 2024-09-15 「php」从零学laravel框架(二):注册登录API
- 2024-09-15 Laravel 5中如何添加Form功能(laravel 伪静态)
- 2024-09-15 告别 $arr[0]: PHP 和 Laravel 中更优雅的数组处理方式
- 2024-09-15 Laravel + Serverless Framework 快速创建 CMS 内容管理系统
- 最近发表
- 标签列表
-
- cmd/c (90)
- c++中::是什么意思 (84)
- 标签用于 (71)
- 主键只能有一个吗 (77)
- c#console.writeline不显示 (95)
- pythoncase语句 (88)
- es6includes (74)
- sqlset (76)
- apt-getinstall-y (100)
- node_modules怎么生成 (87)
- chromepost (71)
- flexdirection (73)
- c++int转char (80)
- mysqlany_value (79)
- static函数和普通函数 (84)
- el-date-picker开始日期早于结束日期 (76)
- js判断是否是json字符串 (75)
- c语言min函数头文件 (77)
- asynccallback (87)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- java (73)
- js数组插入 (83)
- mac安装java (72)
- 无效的列索引 (74)