英文:
Upgrading Laravel from 9 to 10. Update files outside of vendor folder
问题
我想将我的现有Laravel 9项目升级到版本10。目标是不仅通过Composer更新供应商文件。此外,我还希望反映项目代码中供应商文件夹之外的更改。
我按照Laravel文档的升级指南来升级我的项目。
这里列出了已更改的文件。
例如,我的app/Console/Kernel.php
应该从
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
变为
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*/
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
}
/**
* Register the commands for the application.
*/
protected function commands(): void
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
英文:
I want to upgrade my already existing Laravel 9 project to Version 10. The goal is, that not only the vendor files update through composer. Additionally I want to reflect the changes in my project's code outside the vendor folder as well.
I followed the Upgrade Guide of the Laravel Documentation to upgrade my project.
Here are the files, that have been changed.
E.g. my app/Console/Kernel.php
should change from
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
to
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*/
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
}
/**
* Register the commands for the application.
*/
protected function commands(): void
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
答案1
得分: 1
以下是翻译好的部分:
The changes to the Laravel new app skeleton can be viewed on Github via their compare tool: https://github.com/laravel/laravel/compare/9.x...10.x
(You can do this locally, using a GUI Git client or the Git command line, as well.)
These changes can be turned into a .patch
file, which you can then use to apply to your app. Github again provides a fairly easy way to do this; https://github.com/laravel/laravel/compare/9.x...10.x.patch.
Once you have a .patch file saved locally, you can apply it within your repo using git apply <path-to-patch-file>
. In most cases, this should apply cleanly.
<sup>This is, to be clear, not a replacement for following the full upgrade guide at https://laravel.com/docs/10.x/upgrade, as it will only make the tweaks necessary for the default app skeleton; it will not update your own code you wrote in Laravel in any way.</sup>
英文:
The changes to the Laravel new app skeleton can be viewed on Github via their compare tool: https://github.com/laravel/laravel/compare/9.x...10.x
(You can do this locally, using a GUI Git client or the Git command line, as well.)
These changes can be turned into a .patch
file, which you can then use to apply to your app. Github again provides a fairly easy way to do this; https://github.com/laravel/laravel/compare/9.x...10.x.patch.
Once you have a .patch file saved locally, you can apply it within your repo using git apply <path-to-patch-file>
. In most cases, this should apply cleanly.
<sup>This is, to be clear, not a replacement for following the full upgrade guide at https://laravel.com/docs/10.x/upgrade, as it will only make the tweaks necessary for the default app skeleton; it will not update your own code you wrote in Laravel in any way.</sup>
答案2
得分: 0
更新这种“示例”文件可能无法自动完成,因为它们可以被项目中的用户编辑,所以它们不在供应商文件夹中。
要更新与PHP相关的语法,如提到的类型提示,您最好使用类似PHP-CS-Fixer的工具,配合适当的规则使用。但是,对于您提到的函数示例,这种工具可能无法正常工作,因为它要求使用PHPDoc 来定义返回类型。
如果您修改了这些文件,可以手动从Laravel存储库中复制这些更改,并将它们调整到您的代码中,这是一种可行的方法。
英文:
Updating these kind of "example" files automatically may not be possible automatically at all since they are editable by users in their projects, that's why they're not in vendor.
Your best bet for updating PHP-related syntax, such as mentioned type hints, may be something like PHP-CS-Fixer with appriopriate rules, but your example of functions wouldn't work with that as that requires old way of defining return types through PHPDoc.
Copying these changes manually from Laravel repository and adjusting them to your code, if you modified those files, is the way to go.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论