Browse Source

Add custom model for pivot table

master
l4p1n 1 year ago
parent
commit
563472038c
Signed by: l4p1n GPG Key ID: 8A2C2F68B58DC35C
6 changed files with 83 additions and 7 deletions
  1. +23
    -0
      _ide_helper_models.php
  2. +1
    -0
      app/Guild.php
  3. +18
    -0
      app/GuildMember.php
  4. +1
    -0
      app/User.php
  5. +37
    -4
      package-lock.json
  6. +3
    -3
      package.json

+ 23
- 0
_ide_helper_models.php View File

@ -180,3 +180,26 @@ namespace App{
class Message extends \Eloquent {}
}
namespace App{
/**
* App\GuildMember
*
* @property int $id
* @property int $user_id
* @property int $guild_id
* @property string|null $nick
* @property string $joined_at
* @property string|null $premium_since
* @method static \Illuminate\Database\Eloquent\Builder|\App\GuildMember newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\GuildMember newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\GuildMember query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\GuildMember whereGuildId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\GuildMember whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\GuildMember whereJoinedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\GuildMember whereNick($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\GuildMember wherePremiumSince($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\GuildMember whereUserId($value)
*/
class GuildMember extends \Eloquent {}
}

+ 1
- 0
app/Guild.php View File

@ -35,6 +35,7 @@ class Guild extends Model
public function members(){
return $this
->belongsToMany(User::class, 'guild_member')
->using(GuildMember::class)
->withPivot('nick', 'joined_at', 'premium_since')
->as('members')
;


+ 18
- 0
app/GuildMember.php View File

@ -0,0 +1,18 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Relations\Pivot;
class GuildMember extends Pivot
{
public $incrementing = true;
protected $dates = [
'joined_at'
];
protected $casts = [
'joined_at' => 'datetime:c'
];
}

+ 1
- 0
app/User.php View File

@ -34,6 +34,7 @@ class User extends Authenticatable
public function guilds(){
return $this
->belongsToMany(Guild::class, 'guild_member')
->using(GuildMember::class)
->withPivot('nick', 'joined_at', 'premium_since')
;
}


+ 37
- 4
package-lock.json View File

@ -5,17 +5,20 @@
"@types/bluebird": {
"version": "3.5.29",
"resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.29.tgz",
"integrity": "sha512-kmVtnxTuUuhCET669irqQmPAez4KFnFVKvpleVRyfC3g+SHD1hIkFZcWLim9BVcwUBLO59o8VZE4yGCmTif8Yw=="
"integrity": "sha512-kmVtnxTuUuhCET669irqQmPAez4KFnFVKvpleVRyfC3g+SHD1hIkFZcWLim9BVcwUBLO59o8VZE4yGCmTif8Yw==",
"dev": true
},
"@types/caseless": {
"version": "0.12.2",
"resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz",
"integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w=="
"integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==",
"dev": true
},
"@types/node": {
"version": "13.1.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.1.2.tgz",
"integrity": "sha512-B8emQA1qeKerqd1dmIsQYnXi+mmAzTB7flExjmy5X1aVAKFNNNDubkavwR13kR6JnpeLp3aLoJhwn9trWPAyFQ=="
"integrity": "sha512-B8emQA1qeKerqd1dmIsQYnXi+mmAzTB7flExjmy5X1aVAKFNNNDubkavwR13kR6JnpeLp3aLoJhwn9trWPAyFQ==",
"dev": true
},
"@types/pg": {
"version": "7.14.1",
@ -46,6 +49,7 @@
"version": "2.48.4",
"resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.4.tgz",
"integrity": "sha512-W1t1MTKYR8PxICH+A4HgEIPuAC3sbljoEVfyZbeFJJDbr30guDspJri2XOaM2E+Un7ZjrihaDi7cf6fPa2tbgw==",
"dev": true,
"requires": {
"@types/caseless": "*",
"@types/node": "*",
@ -57,6 +61,7 @@
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
"integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==",
"dev": true,
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.6",
@ -69,6 +74,7 @@
"version": "4.1.45",
"resolved": "https://registry.npmjs.org/@types/request-promise/-/request-promise-4.1.45.tgz",
"integrity": "sha512-KFagTY/a7CzAj86DkhaAtqP0ViYTNam+CfEokSwtPFUIuq9Qrq+Rq2X4nuaB6OJmM2s0xWeiS085Ro7vR0tt9Q==",
"dev": true,
"requires": {
"@types/bluebird": "*",
"@types/request": "*"
@ -78,6 +84,7 @@
"version": "1.0.17",
"resolved": "https://registry.npmjs.org/@types/request-promise-native/-/request-promise-native-1.0.17.tgz",
"integrity": "sha512-05/d0WbmuwjtGMYEdHIBZ0tqMJJQ2AD9LG2F6rKNBGX1SSFR27XveajH//2N/XYtual8T9Axwl+4v7oBtPUZqg==",
"dev": true,
"requires": {
"@types/request": "*"
}
@ -85,7 +92,8 @@
"@types/tough-cookie": {
"version": "2.3.6",
"resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.6.tgz",
"integrity": "sha512-wHNBMnkoEBiRAd3s8KTKwIuO9biFtTf0LehITzBhSco+HQI0xkXZbLOD55SW3Aqw3oUkHstkm5SPv58yaAdFPQ=="
"integrity": "sha512-wHNBMnkoEBiRAd3s8KTKwIuO9biFtTf0LehITzBhSco+HQI0xkXZbLOD55SW3Aqw3oUkHstkm5SPv58yaAdFPQ==",
"dev": true
},
"@types/winston": {
"version": "2.4.4",
@ -278,6 +286,11 @@
"kuler": "1.0.x"
}
},
"double-ended-queue": {
"version": "2.1.0-0",
"resolved": "https://registry.npmjs.org/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz",
"integrity": "sha1-ED01J/0xUo9AGIEwyEHv3XgmTlw="
},
"ecc-jsbn": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
@ -636,6 +649,26 @@
"util-deprecate": "^1.0.1"
}
},
"redis": {
"version": "2.8.0",
"resolved": "https://registry.npmjs.org/redis/-/redis-2.8.0.tgz",
"integrity": "sha512-M1OkonEQwtRmZv4tEWF2VgpG0JWJ8Fv1PhlgT5+B+uNq2cA3Rt1Yt/ryoR+vQNOQcIEgdCdfH0jr3bDpihAw1A==",
"requires": {
"double-ended-queue": "^2.1.0-0",
"redis-commands": "^1.2.0",
"redis-parser": "^2.6.0"
}
},
"redis-commands": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.5.0.tgz",
"integrity": "sha512-6KxamqpZ468MeQC3bkWmCB1fp56XL64D4Kf0zJSwDZbVLLm7KFkoIcHrgRvQ+sk8dnhySs7+yBg94yIkAK7aJg=="
},
"redis-parser": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-2.6.0.tgz",
"integrity": "sha1-Uu0J2srBCPGmMcB+m2mUHnoZUEs="
},
"request": {
"version": "2.88.0",
"resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz",


+ 3
- 3
package.json View File

@ -7,12 +7,12 @@
"@types/pg-pool": "^2.0.1",
"@types/winston": "^2.4.4",
"@types/ws": "^6.0.4",
"cross-env": "^5.1"
},
"dependencies": {
"@types/request": "^2.48.4",
"@types/request-promise": "^4.1.45",
"@types/request-promise-native": "^1.0.17",
"cross-env": "^5.1"
},
"dependencies": {
"pg": "^7.17.0",
"pg-pool": "^2.0.9",
"request": "^2.88.0",


Loading…
Cancel
Save