first commit
This commit is contained in:
41
app/Models/Comment.php
Normal file
41
app/Models/Comment.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
//columns that are fillable in the table
|
||||
protected $fillable = [
|
||||
"content",
|
||||
'user_id',
|
||||
'post_id'
|
||||
];
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Get the post that the comment belongs to.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function post(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Post::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user that authored the comment.
|
||||
* If the user is not found, return a default guest author.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class)->withDefault([
|
||||
'name' => 'Guest Author',
|
||||
]);
|
||||
}
|
||||
}
|
||||
42
app/Models/Post.php
Normal file
42
app/Models/Post.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Post extends Model
|
||||
{
|
||||
|
||||
use HasFactory;
|
||||
|
||||
//columns that are fillable in the table
|
||||
protected $fillable = [
|
||||
"content",
|
||||
'user_id'
|
||||
];
|
||||
/**
|
||||
* Get the user that authored the post.
|
||||
* If the user is not found, return a default guest author.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class)->withDefault([
|
||||
'name' => 'Guest Author',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the comments for the post.
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function comments(): HasMany
|
||||
{
|
||||
return $this->hasMany(Comment::class);
|
||||
}
|
||||
}
|
||||
69
app/Models/User.php
Normal file
69
app/Models/User.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
protected $connection = 'sqlsrv';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'fname',
|
||||
'mname',
|
||||
'lname',
|
||||
'position',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the posts authored by the user.
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function posts(): HasMany
|
||||
{
|
||||
return $this->hasMany(Post::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the comments authored by the user.
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function comments(): HasMany
|
||||
{
|
||||
return $this->hasMany(Comment::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user