|
@@ -11,19 +11,27 @@ namespace App\Http\Controllers;
|
|
|
use App\Http\Requests\PostRequest;
|
|
|
use App\Jobs\SendMailJob;
|
|
|
use App\Post;
|
|
|
+use App\Services\PostService;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
|
|
class PostsController extends Controller
|
|
|
{
|
|
|
+ protected $postService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * PostsController constructor.
|
|
|
+ */
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->postService = new PostService();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
*/
|
|
|
public function index()
|
|
|
{
|
|
|
-
|
|
|
- SendMailJob::dispatch('the9thlaw@ukr.net');
|
|
|
-
|
|
|
$posts = Post::all();
|
|
|
|
|
|
return view('posts.index', [
|
|
@@ -57,11 +65,7 @@ class PostsController extends Controller
|
|
|
*/
|
|
|
public function store(PostRequest $request)
|
|
|
{
|
|
|
- $post = new Post();
|
|
|
- $post->fill($request->all() + [
|
|
|
- 'user_id' => Auth::id(),
|
|
|
- ]);
|
|
|
- $post->save();
|
|
|
+ $this->postService->create($request->all());
|
|
|
|
|
|
return redirect(route('posts.index'));
|
|
|
}
|