Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/Http/Controllers/Personal/Comment/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

use App\Http\Controllers\Controller;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Contracts\Auth\Authenticatable;

class IndexController extends Controller
{
public function __invoke(ViewFactory $view_factory)
public function __invoke(ViewFactory $view_factory, Authenticatable $user)
{
/** @phpstan-ignore-next-line */
$comments = auth()->user()->comments;
$comments = $user->comments;

return $view_factory->make('personal.comment.index', ['comments' => $comments]);
}
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/Personal/Liked/DeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

use App\Http\Controllers\Controller;
use App\Models\Post;
use Illuminate\Contracts\Auth\Authenticatable;

class DeleteController extends Controller
{
public function __invoke(Post $post)
public function __invoke(Post $post, Authenticatable $user)
{
/** @phpstan-ignore-next-line */
auth()->user()->likedPosts()->detach($post->id);
$user->likedPosts()->detach($post->id);

return redirect()->route('personal.liked.index');
}
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/Personal/Liked/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace App\Http\Controllers\Personal\Liked;

use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\View\Factory as ViewFactory;

class IndexController extends Controller
{
public function __invoke(ViewFactory $view_factory)
public function __invoke(ViewFactory $view_factory, Authenticatable $user)
{
/** @phpstan-ignore-next-line */
$posts = auth()->user()->likedPosts;
$posts = $user->likedPosts;

return $view_factory->make('personal.liked.index', ['posts' => $posts]);
}
Expand Down
7 changes: 4 additions & 3 deletions app/Http/Controllers/Personal/Main/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
namespace App\Http\Controllers\Personal\Main;

use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\View\Factory as ViewFactory;

class IndexController extends Controller
{
public function __invoke(ViewFactory $view_factory)
public function __invoke(ViewFactory $view_factory, Authenticatable $user)
{
/** @phpstan-ignore-next-line */
$data['countComments'] = count(auth()->user()->comments);
$data['countComments'] = count($user->comments);
/** @phpstan-ignore-next-line */
$data['countLiked'] = count(auth()->user()->likedPosts);
$data['countLiked'] = count($user->likedPosts);

return $view_factory->make('personal.main.index', ['data' => $data]);
}
Expand Down
9 changes: 5 additions & 4 deletions app/Http/Controllers/Post/Comment/StoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
use App\Http\Requests\Post\Comment\StoreRequest;
use App\Models\Comment;
use App\Models\Post;
use Illuminate\Contracts\Auth\Authenticatable;

class StoreController extends Controller
{
public function __invoke(StoreRequest $request, Post $post)
public function __invoke(StoreRequest $request, Post $post, Authenticatable $user)
{
$data = $request->validated();
$data = $request->validated();
$data['post_id'] = $post->id;
/** @phpstan-ignore-next-line */
$data['user_id'] = auth()->user()->id;
/** @phpstan-ignore-next-line */
$data['user_id'] = $user->id;
/** @phpstan-ignore-next-line */
Comment::create($data);

Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/Post/Like/StoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

use App\Http\Controllers\Controller;
use App\Models\Post;
use Illuminate\Contracts\Auth\Authenticatable;

class StoreController extends Controller
{
public function __invoke(Post $post)
public function __invoke(Post $post, Authenticatable $user)
{
/** @phpstan-ignore-next-line */
auth()->user()->likedPosts()->toggle($post->id);
$user->likedPosts()->toggle($post->id);

return redirect()->back();
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Middleware/AdminMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
*/
public function handle(Request $request, Closure $next): Response
{
$user = $request->user();
/** @phpstan-ignore-next-line */
if (auth()->user()->isReader()) {
if (! $user || ! $user->isAdministrator()) {

Check failure on line 20 in app/Http/Middleware/AdminMiddleware.php

View workflow job for this annotation

GitHub Actions / Analyze

No error to ignore is reported on line 20.
abort(404);
}

Expand Down
4 changes: 2 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
Route::prefix('post')->namespace('')->group(function () {
Route::get('/{post}', [PostController::class, 'show'])->name('post.show');

Route::prefix('{post}/comments')->group(function () {
Route::prefix('{post}/comments')->middleware('auth')->group(function () {
Route::post('/', 'App\Http\Controllers\Post\Comment\StoreController')->name('post.comments.store');
});
Route::prefix('{post}/likes')->group(function () {
Route::prefix('{post}/likes')->middleware('auth')->group(function () {
Route::post('/', 'App\Http\Controllers\Post\Like\StoreController')->name('post.likes.store');
});
});
Expand Down
Loading