-1

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');
    }
}
JanBoehmer
  • 395
  • 3
  • 14

2 Answers2

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.

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.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
0

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.

Destroy666
  • 892
  • 12
  • 19
  • Understand. So the two possibilities I have are 1) manually 1 by 1 or 2) pay (or build something shift-like myself, where I'd better stick with 1 Isn't there something like `git merge the code from Laravel's github` or something like that? I don't want to check every single change. I want to merge everything like I would have started from a fresh new Laravel 10 project – JanBoehmer Feb 16 '23 at 10:56
  • 1
    That's what composer does. It merges the source code from Laravel into vendor folder of your project, as you noticed. But you need to adjust your project is there are breaking changes. – Destroy666 Feb 16 '23 at 11:49
  • That's what my question is about. The Laravel Repo (https://github.com/laravel/laravel) has all theses changes. I could download it as a zip, copy it in my project and replace the files. and git would show me the differences, or what has been removed. But a merge would be better. – JanBoehmer Feb 16 '23 at 12:37
  • 1
    I would recommend having a read about how `composer.json`, `composer.lock` and `vendor` work. E.g. here https://getcomposer.org/doc/01-basic-usage.md As these questions don't make much sense if it's not about breaking changes - the most basic Composer/package manager knowledge is recommended to upgrade libraries in your project. In short: you should never have vendor files in your repo – Destroy666 Feb 16 '23 at 12:45
  • I think you don't understand my question. I know how composer works and I know that composer updates inside the vendor folder. But what I want, e.g. my `app/Console/Kernel.php` `protected function schedule(Schedule $schedule)` should change to `protected function schedule(Schedule $schedule) : void`, because this is what you would have, if you install Laravel 10 fresh. This has nothing to do with composer in my eyes. – JanBoehmer Feb 16 '23 at 12:57
  • That would have been a lot better description with an example initially - I would recommend updating the question. But my initial answer kind of covers it, although from a bit different angle - it's changes you need to do manually. This example is basically just adding a return type to some functions and it's more related to PHP than Laravel. – Destroy666 Feb 16 '23 at 13:42
  • 1
    Thank you for the tipp. I updated my question accordingly to add more clarity. – JanBoehmer Feb 16 '23 at 14:17
  • "It's up to you" is not something you should start your answer with. Provide precise instructions about how to resolve a problem – Nico Haase Feb 16 '23 at 14:23
  • Great! Note that 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 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. – Destroy666 Feb 16 '23 at 14:27
  • @Nico Haase the answer was accurate because it mentioned following changes manually - nothing else you can add there... Wording nitpicking doesn't bring anything IMO. But I'm editing the answer to reflect the actual question now. – Destroy666 Feb 16 '23 at 14:32
  • The original answer didn't mention a single **specific** step – Nico Haase Feb 16 '23 at 14:42