Repository: laravel/framework (php)

Issue:
ValidatesAttributes::parseTable treats table schema prefix as connection
- Laravel Version: 8.44.0
- PHP Version: 7.4.3
- Database Driver & Version: MySQL 8.0.25

### Description:
In order to be able to share some functionality between our enterprise environment we have multiple schema in our databases servers, and share some models and services via packages. Today when trying to use the Rule::unique('public.users') or even Rule::unique(User::class) the framework always throws the error "Database connection [public] not configured."

```php
class User extends BaseModel {
    protected $table = 'public.users';
}
```

I already forked the repository and added a fix to that problem, with a unit test to validate so that if a table has a '.' and the $connection is the same as the prefix, it sets the $connection to null, but I decided to create this issue to check if the current behavior (where the $table prefix is treated like a connection) is the intended behavior before submitting a PR



Pull request:
[8.x] Add missing fix to DatabaseRule::resolveTableName fix #37580
In my previous PR (#37606) I didn't noticed that the trait `DatabaseRule` has it's own `resolveTableName` method, and I did not apply the fixes there. This pull request adds the same fix to this trait. 

Patch:
diff --git a/src/Illuminate/Database/DatabaseTransactionsManager.php b/src/Illuminate/Database/DatabaseTransactionsManager.php
index 156514de60..add2f7c1a6 100755
--- a/src/Illuminate/Database/DatabaseTransactionsManager.php
+++ b/src/Illuminate/Database/DatabaseTransactionsManager.php
@@ -58,15 +58,15 @@ public function rollback($connection, $level)
      */
     public function commit($connection)
     {
-        $this->transactions = $this->transactions->reject(function ($transaction) use ($connection) {
-            if ($transaction->connection == $connection) {
-                $transaction->executeCallbacks();
-
-                return true;
+        [$forThisConnection, $forOtherConnections] = $this->transactions->partition(
+            function ($transaction) use ($connection) {
+                return $transaction->connection == $connection;
             }
+        );
 
-            return false;
-        })->values();
+        $this->transactions = $forOtherConnections->values();
+
+        $forThisConnection->map->executeCallbacks();
     }
 
     /**
diff --git a/src/Illuminate/Support/Facades/Session.php b/src/Illuminate/Support/Facades/Session.php
index 12a4547a1f..a072321691 100755
--- a/src/Illuminate/Support/Facades/Session.php
+++ b/src/Illuminate/Support/Facades/Session.php
@@ -13,7 +13,7 @@
  * @method static bool save()
  * @method static bool start()
  * @method static mixed get(string $key, $default = null)
- * @method static mixed flash(string $class, string $message)
+ * @method static mixed flash(string $key, $value = true)
  * @method static mixed pull(string $key, $default = null)
  * @method static mixed remove(string $key)
  * @method static string getId()
diff --git a/src/Illuminate/Validation/Rules/DatabaseRule.php b/src/Illuminate/Validation/Rules/DatabaseRule.php
index b8113b2afa..7789008483 100644
--- a/src/Illuminate/Validation/Rules/DatabaseRule.php
+++ b/src/Illuminate/Validation/Rules/DatabaseRule.php
@@ -65,6 +65,10 @@ public function resolveTableName($table)
         if (is_subclass_of($table, Model::class)) {
             $model = new $table;
 
+            if (Str::contains($model->getTable(), '.')) {
+                return $table;
+            }
+
             return implode('.', array_map(function (string $part) {
                 return trim($part, '.');
             }, array_filter([$model->getConnectionName(), $model->getTable()])));


Test patch:
diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php
index 86da0dcfd7..d01994e3cc 100644
--- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php
+++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php
@@ -134,7 +134,9 @@ public function castAsJson($value)
             $value = json_encode($value);
         }
 
-        return DB::raw("CAST('$value' AS JSON)");
+        $value = DB::connection()->getPdo()->quote($value);
+
+        return DB::raw("CAST($value AS JSON)");
     }
 
     /**
diff --git a/tests/Validation/ValidationExistsRuleTest.php b/tests/Validation/ValidationExistsRuleTest.php
index 77918ce399..ee85dd322c 100644
--- a/tests/Validation/ValidationExistsRuleTest.php
+++ b/tests/Validation/ValidationExistsRuleTest.php
@@ -43,6 +43,10 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule()
         $rule->where('foo', 'bar');
         $this->assertSame('exists:users,NULL,foo,"bar"', (string) $rule);
 
+        $rule = new Exists(UserWithPrefixedTable::class);
+        $rule->where('foo', 'bar');
+        $this->assertSame('exists:'.UserWithPrefixedTable::class.',NULL,foo,"bar"', (string) $rule);
+
         $rule = new Exists('table', 'column');
         $rule->where('foo', 'bar');
         $this->assertSame('exists:table,column,foo,"bar"', (string) $rule);
@@ -235,6 +239,13 @@ class User extends Eloquent
     public $timestamps = false;
 }
 
+class UserWithPrefixedTable extends Eloquent
+{
+    protected $table = 'public.users';
+    protected $guarded = [];
+    public $timestamps = false;
+}
+
 class UserWithConnection extends User
 {
     protected $connection = 'mysql';
diff --git a/tests/Validation/ValidationUniqueRuleTest.php b/tests/Validation/ValidationUniqueRuleTest.php
index c1545887db..2aa821c1f6 100644
--- a/tests/Validation/ValidationUniqueRuleTest.php
+++ b/tests/Validation/ValidationUniqueRuleTest.php
@@ -35,6 +35,9 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule()
         $rule->where('foo', 'bar');
         $this->assertSame('unique:table,column,"Taylor, Otwell",id_column,foo,"bar"', (string) $rule);
 
+        $rule = new Unique(PrefixedTableEloquentModelStub::class);
+        $this->assertSame('unique:'.PrefixedTableEloquentModelStub::class.',NULL,NULL,id', (string) $rule);
+
         $rule = new Unique(EloquentModelStub::class, 'column');
         $rule->ignore('Taylor, Otwell', 'id_column');
         $rule->where('foo', 'bar');
@@ -87,6 +90,13 @@ class EloquentModelStub extends Model
     protected $guarded = [];
 }
 
+class PrefixedTableEloquentModelStub extends Model
+{
+    protected $table = 'public.table';
+    protected $primaryKey = 'id_column';
+    protected $guarded = [];
+}
+
 class NoTableName extends Model
 {
     protected $guarded = [];