Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog responses #102

Merged
merged 10 commits into from
Aug 2, 2022
19 changes: 19 additions & 0 deletions app/Http/Controllers/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Models\Response;
use Illuminate\Http\Request;
use Str;

Expand Down Expand Up @@ -140,4 +141,22 @@ public function disableReplies($slug) //POST
);
return redirect(route('blog.hidden'));
}

public function response($slug, Request $request) // POST REQUEST
{
$id = \App\Models\Blog::query()
->where('slug', $slug)
->first()->id;

Response::query()
->create(
[
'user_id' => auth()->id(),
'blog_id' => $id,
'response' => $request->input('comment')
]
);

return redirect(route('blog.show', $slug));
}
}
5 changes: 5 additions & 0 deletions app/Models/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public function User()
{
return $this->belongsTo(User::class);
}

public function Response()
{
return $this->hasMany(Response::class);
}
}
27 changes: 27 additions & 0 deletions app/Models/Response.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Response extends Model
{
use HasFactory;

protected $fillable = [
'user_id',
'blog_id',
'response'
];

public function Blog()
{
return $this->belongsTo(Blog::class);
}

public function User()
{
return $this->belongsTo(User::class);
}
}
Loading