Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 8 Project is not opening in the server..getting error in TestDatabases.php

I am Getting error when I open the laravel 8 project

 protected function switchToDatabase($database)
    {
        DB::purge();
 
        $default = config('database.default');
 
        config()->set(
            "database.connections.{$default}.database",
            $database,
        );
    }

"syntax error, unexpected ')'" in vendor/laravel/framework/src/Illuminate/Testing/Concerns/TestDatabases.php

like image 635
Prem ThAqqar Avatar asked Jan 29 '21 08:01

Prem ThAqqar


3 Answers

Gert B. answer does solve the situation, but you should instead update your PHP to version 7.3 or higher, as Mohammad mentioned, to solve this. Changing platform/vendor code is not the best option.

like image 166
Hugo S Avatar answered Nov 08 '22 13:11

Hugo S


You're using a PHP version lower than 7.3

in: vendor/laravel/framework/src/Illuminate/Testing/Concerns/TestDatabases.php

Change:

    if ($url) {
        config()->set(
            "database.connections.{$default}.url",
            preg_replace('/^(.*)(\/[\w-]*)(\??.*)$/', "$1/{$database}$3", $url),
        );
    } else {
        config()->set(
            "database.connections.{$default}.database",
            $database,
        );
    }

to:

    if ($url) {
        config()->set(
            "database.connections.{$default}.url",
            preg_replace('/^(.*)(\/[\w-]*)(\??.*)$/', "$1/{$database}$3", $url)
        );
    } else {
        config()->set(
            "database.connections.{$default}.database",
            $database
        );
    }

Removing the comma at the end of line fixes the issue.

like image 10
Mohammad Fanni Avatar answered Nov 08 '22 13:11

Mohammad Fanni


remove the trailing "," in your set function call:

config()->set(
        "database.connections.{$default}.database",
        $database
    );
like image 6
Gert B. Avatar answered Nov 08 '22 13:11

Gert B.