1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Schema; |
6
|
|
|
use Illuminate\Database\Schema\Blueprint; |
7
|
|
|
use Illuminate\Database\Migrations\Migration; |
8
|
|
|
|
9
|
|
|
class CreateStatisticsRequestsTable extends Migration |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Run the migrations. |
13
|
|
|
* |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
|
|
public function up(): void |
17
|
|
|
{ |
18
|
|
|
Schema::create(config('rinvex.statistics.tables.requests'), function (Blueprint $table) { |
19
|
|
|
// Columns |
20
|
|
|
$table->increments('id'); |
21
|
|
|
$table->integer('route_id')->unsigned(); |
22
|
|
|
$table->integer('agent_id')->unsigned(); |
23
|
|
|
$table->integer('device_id')->unsigned(); |
24
|
|
|
$table->integer('platform_id')->unsigned(); |
25
|
|
|
$table->integer('path_id')->unsigned(); |
26
|
|
|
$table->integer('geoip_id')->unsigned(); |
27
|
|
|
$table->nullableMorphs('user'); |
28
|
|
|
$table->string('session_id'); |
29
|
|
|
$table->integer('status_code'); |
30
|
|
|
$table->string('protocol_version')->nullable(); |
31
|
|
|
$table->text('referer')->nullable(); |
32
|
|
|
$table->string('language'); |
33
|
|
|
$table->boolean('is_no_cache')->default(0); |
34
|
|
|
$table->boolean('wants_json')->default(0); |
35
|
|
|
$table->boolean('is_secure')->default(0); |
36
|
|
|
$table->boolean('is_json')->default(0); |
37
|
|
|
$table->boolean('is_ajax')->default(0); |
38
|
|
|
$table->boolean('is_pjax')->default(0); |
39
|
|
|
$table->timestamp('created_at')->nullable(); |
40
|
|
|
|
41
|
|
|
// Indexes |
42
|
|
|
$table->foreign('route_id')->references('id')->on(config('rinvex.statistics.tables.routes')) |
|
|
|
|
43
|
|
|
->onDelete('cascade')->onUpdate('cascade'); |
44
|
|
|
$table->foreign('agent_id')->references('id')->on(config('rinvex.statistics.tables.agents')) |
45
|
|
|
->onDelete('cascade')->onUpdate('cascade'); |
46
|
|
|
$table->foreign('device_id')->references('id')->on(config('rinvex.statistics.tables.devices')) |
47
|
|
|
->onDelete('cascade')->onUpdate('cascade'); |
48
|
|
|
$table->foreign('platform_id')->references('id')->on(config('rinvex.statistics.tables.platforms')) |
49
|
|
|
->onDelete('cascade')->onUpdate('cascade'); |
50
|
|
|
$table->foreign('path_id')->references('id')->on(config('rinvex.statistics.tables.paths')) |
51
|
|
|
->onDelete('cascade')->onUpdate('cascade'); |
52
|
|
|
$table->foreign('geoip_id')->references('id')->on(config('rinvex.statistics.tables.geoips')) |
53
|
|
|
->onDelete('cascade')->onUpdate('cascade'); |
54
|
|
|
}); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Reverse the migrations. |
59
|
|
|
* |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
|
|
public function down(): void |
63
|
|
|
{ |
64
|
|
|
Schema::dropIfExists(config('rinvex.statistics.tables.requests')); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get jsonable column data type. |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
protected function jsonable(): string |
73
|
|
|
{ |
74
|
|
|
$driverName = DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME); |
75
|
|
|
$dbVersion = DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION); |
76
|
|
|
$isOldVersion = version_compare($dbVersion, '5.7.8', 'lt'); |
77
|
|
|
|
78
|
|
|
return $driverName === 'mysql' && $isOldVersion ? 'text' : 'json'; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: