32

I have this laravel api hosted on a sharefd hosting siteground, i made some changes like changing the public folder to public html and update the storage filing so i can be able to run the laravel storage link commande bu i encountred this error while trying to access my temporary domain

FULL ERROR NAME Carbon\Carbon::setLastErrors(): Argument #1 ($lastErrors) must be of type array, bool given, called in /home/customer/www/bassemb5.sg-host.com/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php on line 98

enter image description here

and this is my index.php looks like

<?php

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Check If The Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is in maintenance / demo mode via the "down" command
| we will load this file so that any pre-rendered content can be shown
| instead of starting the framework, which could cause an exception.
|
*/

if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
    require $maintenance;
}

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/

require __DIR__.'/../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';
$app->bind('path.public', fn() => base_path('/public_html'));

$kernel = $app->make(Kernel::class);

$response = $kernel->handle(
    $request = Request::capture()
)->send();
$kernel->terminate($request, $response);

and this is the line i added and it was working perfectly $app->bind('path.public', fn() => base_path('/public_html'));

11 Answers 11

67

Hi Also managing my old site. You need to update your composer by using

composer update

And all work fine

1
  • Hero. Should be first step in any laravel issue, applies to Nova as well. It's the least invasive solution, and fastest to evaluate. Worked for me, thanks again Ahmed! Commented Feb 24, 2023 at 10:50
20

If you can not change your PHP version to 8.1, you can update this line

File Path

./vendor/nesbot/carbon/src/Carbon/Traits/Creator.php

Line No:

928

Old Line

private static function setLastErrors(array $lastErrors)

New Line


private static function setLastErrors($lastErrors)
1
  • 2
    This is terrible advice. Never change vendor files.
    – miken32
    Commented Apr 20 at 21:31
16

We had exactly the same error (same file and line) than OP.

In our research it looks like it got broken after 2.57 (working), for us 2.58 was already failing and broke our pipeline, failing in the "composer install" phase with exactly same error.

As @tomexsans mentions it seems to be fixed in 2.62.1+. We upgraded to the latest available version today (2.64) and worked fine, getting the issue fixed.

--

TL;DR

composer update nesbot/carbon

should do the trick.

1
15

Also managing my old site on Siteground, customer contacted told me about 500 error.

  • When I looked at the Logs nothing is wrong.
  • When I turned on the app_debug we had the same error.

It does not happen on localhost because I have PHP 8.1 installed.

If you're using PHP 8.2 and this problem appears, you need to update your composer.lock to the latest carbon version

https://github.com/briannesbitt/Carbon/releases/tag/2.62.1

or just pull back your PHP version to 8.1

UPDATE: this error came from Siteground Auto Updating your PHP VERSION to 8.2

I have mine forced to PHP 8.1 yet they still Auto Managed it and upgraded the PHP Version to 8.2 without any notifications or advise

1
  • I am using the laravel sail. The error went away after changing 8.2 to 8.1 Commented Feb 25, 2023 at 12:17
13

I had this issue a few days again just type composer update on your terminal that will solve the issue.

3

Simply run this command:

composer update

It will work.

2

I just solve this problem by downgrade version of PHP from 8.2 to 8.0.2

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Oct 24, 2023 at 15:27
1

We used carbon in combination with aporat - store receipt validator. Unfortunately we couldn't update the nesbot using composer, due hardlocked versions and nesbot being a dependency of another library.

Luckily when comparing the libraries Creator file we saw the hotfix in the latest version, by that time being: https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/Traits/Creator.php

We ended up fixing it with only updating that specific file, since only the setLastErrors() function was updated there.

I truly hope it helps someone.

3
  • I just remove array type hint in this line “private static function setLastErrors(array $lastErrors)” to “ private static function setLastErrors($lastErrors)” and it work. Commented Jan 11, 2023 at 7:07
  • the problem with this fix is when you forget and run composer update it will overwrite the file you have changed. Make sure this is pretty documented. for future DEVS.
    – tomexsans
    Commented Jan 19, 2023 at 14:45
  • Totally agree with @tomexsans - Even though carbon already patched its own mistake, libraries as Store receipt validator still need to update their own Carbon dependency. So not only the future devs but I also made sure to notify aporat of this error. Commented Jan 20, 2023 at 10:31
0

Make sure you are using the correct php version as the composer.json file says.

To know your version of php just run:

php -v

In Homestead, for example, to change the 7.4 php version just run the command:

php74
0

This issue arises when using PHP versions 8.2 and above.

In my particular situation, I resolved this issue by simply switching to PHP version 8.1, which automatically resolved the problem.

0

step1: Just run composer update step2: you will be able to past a token, by generated on your github account and run it, you will see message like "token stored successfull" on your command line

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Feb 14 at 11:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.