|
@@ -2,31 +2,36 @@
|
|
|
|
|
|
namespace App;
|
|
namespace App;
|
|
|
|
|
|
-use Illuminate\Http\Request;
|
|
|
|
|
|
+class Post extends Model
|
|
|
|
+{
|
|
|
|
|
|
-class Post extends Model {
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * These fields are OK for mass assignement.
|
|
|
|
- *
|
|
|
|
- * @var array
|
|
|
|
- */
|
|
|
|
- protected $fillable = ['body', 'title'];
|
|
|
|
|
|
+ /**
|
|
|
|
+ * These fields are OK for mass assignement.
|
|
|
|
+ *
|
|
|
|
+ * @var array
|
|
|
|
+ */
|
|
|
|
+ protected $fillable = ['body', 'title'];
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param string $body
|
|
* @param string $body
|
|
*/
|
|
*/
|
|
- public function addComment(string $body) {
|
|
|
|
|
|
+ public function addComment(string $body)
|
|
|
|
+ {
|
|
// Comment::create([
|
|
// Comment::create([
|
|
// 'body' => $body,
|
|
// 'body' => $body,
|
|
// 'post_id' => $this->id,
|
|
// 'post_id' => $this->id,
|
|
// ]);
|
|
// ]);
|
|
|
|
|
|
$this->comments()->create(compact('body'));
|
|
$this->comments()->create(compact('body'));
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function comments()
|
|
|
|
+ {
|
|
|
|
+ return $this->hasMany(Comment::class);
|
|
|
|
+ }
|
|
|
|
|
|
- public function comments()
|
|
|
|
- {
|
|
|
|
- return $this->hasMany(Comment::class);
|
|
|
|
- }
|
|
|
|
|
|
+ public function user()
|
|
|
|
+ {
|
|
|
|
+ return $this->belongsTo(User::class);
|
|
|
|
+ }
|
|
}
|
|
}
|