-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding post, comment and adjusting user model
- Loading branch information
1 parent
cc70e05
commit 9b36804
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Comment extends Model | ||
{ | ||
use HasFactory; | ||
|
||
/** | ||
* The user who wrote the comment | ||
* | ||
* @return App\Models\User | ||
*/ | ||
public function author() | ||
{ | ||
return $this->belongsTo('App\Models\User', 'user_id'); | ||
} | ||
|
||
/** | ||
* The post the comment is associated with | ||
* | ||
* @return App\Models\Post | ||
*/ | ||
public function post() | ||
{ | ||
return $this->belongsTo('App\Models\Posts', 'post_id'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Post extends Model | ||
{ | ||
use HasFactory; | ||
|
||
/** | ||
* Get the comments made on the post | ||
* | ||
* @return array App\Models\Comment | ||
*/ | ||
public function comments() | ||
{ | ||
return $this->hasMany('App\Models\Comments', 'post_id'); | ||
} | ||
|
||
/** | ||
* Get the user who created the post | ||
* | ||
* @return App\Models\User | ||
*/ | ||
public function author() | ||
{ | ||
return $this->belongsTo('App\Models\User', 'user_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters