Skip to content

Commit

Permalink
Making eloquent models for previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jayar95 committed Mar 6, 2018
1 parent c2949ae commit bc8aeb2
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 54 deletions.
28 changes: 0 additions & 28 deletions app/Http/Controllers/HomeController.php

This file was deleted.

14 changes: 12 additions & 2 deletions app/Riddle.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Riddle extends Model {
//
protected $fillable = [
'content',
'title',
'winner',
];

/**
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function winner() {
return $this->hasOne('App\User', 'winner');
}
}
13 changes: 11 additions & 2 deletions app/RiddleAnswer.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class RiddleAnswer extends Model {
//
protected $fillable = [
'riddle_id',
'answer',
];

/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function riddle() {
return $this->belongsTo('App\Riddle');
}
}
10 changes: 8 additions & 2 deletions app/Submission.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Submission extends Model {
//
protected $fillable = [
'user_id',
'answer'
];

public function user() {
return $this->belongsTo('App\User');
}
}
40 changes: 22 additions & 18 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,6 @@
class User extends Authenticatable implements JWTSubject {
use Notifiable;

/**
* Get the identifier that will be stored in the subject claim of the JWT.
*
* @return mixed
*/
public function getJWTIdentifier() {
return $this->getKey();
}

/**
* Return a key value array, containing any custom claims to be added to the JWT.
*
* @return array
*/
public function getJWTCustomClaims() {
return [];
}

/**
* The attributes that are mass assignable.
*
Expand All @@ -47,4 +29,26 @@ public function getJWTCustomClaims() {
'password',
'remember_token',
];

public function submissions() {
return $this->hasMany('App\Submission');
}

/**
* Get the identifier that will be stored in the subject claim of the JWT.
*
* @return mixed
*/
public function getJWTIdentifier() {
return $this->getKey();
}

/**
* Return a key value array, containing any custom claims to be added to the JWT.
*
* @return array
*/
public function getJWTCustomClaims() {
return [];
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
Expand Down

0 comments on commit bc8aeb2

Please sign in to comment.