Completed
Push — master ( e4d660...050514 )
by Abdelrahman
02:52 queued 01:47
created

...5_03_204353_create_plan_subscriptions_table.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
use Illuminate\Database\Schema\Blueprint;
6
use Illuminate\Database\Migrations\Migration;
7
8
class CreatePlanSubscriptionsTable extends Migration
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /**
11
     * Run the migrations.
12
     *
13
     * @return void
14
     */
15
    public function up(): void
16
    {
17
        Schema::create(config('rinvex.subscriptions.tables.plan_subscriptions'), function (Blueprint $table) {
18
            $table->increments('id');
19
            $table->morphs('user');
20
            $table->integer('plan_id')->unsigned();
21
            $table->string('slug');
22
            $table->{$this->jsonable()}('name');
23
            $table->{$this->jsonable()}('description')->nullable();
24
            $table->dateTime('trial_ends_at')->nullable();
25
            $table->dateTime('starts_at')->nullable();
26
            $table->dateTime('ends_at')->nullable();
27
            $table->dateTime('cancels_at')->nullable();
28
            $table->dateTime('canceled_at')->nullable();
29
            $table->string('timezone')->nullable();
30
            $table->timestamps();
31
            $table->softDeletes();
32
33
            // Indexes
34
            $table->unique('slug');
35
            $table->foreign('plan_id')->references('id')->on(config('rinvex.subscriptions.tables.plans'))
36
                  ->onDelete('cascade')->onUpdate('cascade');
37
        });
38
    }
39
40
    /**
41
     * Reverse the migrations.
42
     *
43
     * @return void
44
     */
45
    public function down(): void
46
    {
47
        Schema::dropIfExists(config('rinvex.subscriptions.tables.plan_subscriptions'));
48
    }
49
50
    /**
51
     * Get jsonable column data type.
52
     *
53
     * @return string
54
     */
55
    protected function jsonable(): string
56
    {
57
        $driverName = DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
58
        $dbVersion = DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
59
        $isOldVersion = version_compare($dbVersion, '5.7.8', 'lt');
60
61
        return $driverName === 'mysql' && $isOldVersion ? 'text' : 'json';
62
    }
63
}
64