'Error when trying to serve Laravel application

I'm trying to serve (php artisan serve) a Laravel application but for some reason I'm getting this fatal error:

PHP Fatal error:  During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Support\Collection.php:1338

Stack trace:

  #1 C:\Program Files\Ampps\www\emotions\vendor\composer\ClassLoader.php(444): include('...')
  #2 C:\Program Files\Ampps\www\emotions\vendor\composer\ClassLoader.php(322): Composer\Autoload\includeFile()
  #3 C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Support\helpers.php(110): Composer\Autoload\ClassLoader->loadClass()
  #4 C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(89): collect()
  #5 C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(78): Illuminate\Foundation\PackageManifest->config()
  #6 C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\RegisterFacades.php(26): Illuminate\Foundation\PackageManifest->aliases()
  #7 C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(230): Illuminate\Foundation\Bootstrap\RegisterFacades->bootstrap()
  #8 C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(310): Illuminate\Foundation\Application->bootstrapWith()
  #9 C:\Program Files\Ampps\www\emotions\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(127): Illuminate\Foundation\Console\Kernel->bootstrap()
  #10 C:\Program Files\Ampps\www\emotions\artisan(37): Illuminate\Foundation\Console\Kernel->handle()
  #11 {main}

Does anyone know what is going on? I've tried upgrading the PHP version the project is using in the composer.json (project is using ^7.2.5 and I'm using 8.1.2) but nothing has worked.



Solution 1:[1]

Update composer.json on your laravel project. like this

{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^7.2|^8.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.40",
"laravel/tinker": "^2.5"
},

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zaman