Skip to content

Commit

Permalink
Better syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
stanfortonski committed Sep 26, 2021
1 parent 89dc9e6 commit 79f5dc4
Show file tree
Hide file tree
Showing 45 changed files with 2,069 additions and 1,513 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/API/AuthorsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class AuthorsController extends Controller
* Display the specified resource.
*
* @param \App\Models\User $user
* @return \Illuminate\Http\Response
* @return \App\Http\Resources\UserResource
*/
public function __invoke(User $user)
public function __invoke(User $user): UserResource
{
return new UserResource($user);
}
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/API/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class CategoriesController extends Controller
* Display a listing of the resource.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
Expand All @@ -25,9 +24,9 @@ public function index(Request $request)
* Display the specified resource.
*
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
* @return \App\Http\Resources\CategoryResource
*/
public function show(Category $category)
public function show(Category $category): CategoryResource
{
if (!empty($category->contents))
return new CategoryResource($category);
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/API/PostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class PostsController extends Controller
* Display a listing of the resource.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
Expand All @@ -25,9 +24,9 @@ public function index(Request $request)
* Display the specified resource.
*
* @param \App\Models\Post $post
* @return \Illuminate\Http\Response
* @return \App\Http\Resources\PostResource
*/
public function show(Post $post)
public function show(Post $post): PostResource
{
if ($post->isVisible() && !empty($post->contents))
return new PostResource($post);
Expand Down
24 changes: 17 additions & 7 deletions app/Http/Controllers/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,38 @@
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Cookie;
use Illuminate\View\View;

class AdminController extends Controller
{
/**
* Handle the incoming request.
* Handle the admin index page.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
* @return \Illuminate\View\View
*/
public function index(Request $request)
public function index(): View
{
return view('admin.index');
}

public function filesManager()
/**
* Handle the file manager page.
*
* @return \Illuminate\View\View
*/
public function filesManager(): View
{
return view('admin.files-manager');
}

public function setLang($lang)
/**
* Handle the change lang method
*
* @return \Illuminate\Http\RedirectResponse
*/
public function setLang(string $lang)
{
Cookie::queue('lang', $lang);
return redirect()->back();
Expand Down
23 changes: 12 additions & 11 deletions app/Http/Controllers/Admin/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\View\View;

class CategoriesController extends Controller
{
Expand All @@ -22,9 +23,9 @@ class CategoriesController extends Controller
* Display a listing of the resource.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
* @return \Illuminate\View\View
*/
public function index(Request $request)
public function index(Request $request): View
{
$categories = Category::with('content')->search($request->q)->paginate(config('blog.pagination'))->withQueryString();
return view('admin.categories.index')->with([
Expand All @@ -36,9 +37,9 @@ public function index(Request $request)
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
* @return \Illuminate\View\View
*/
public function create()
public function create(): View
{
return view('admin.categories.save');
}
Expand All @@ -47,7 +48,7 @@ public function create()
* Store a newly created resource in storage.
*
* @param \App\Requests\CategoryStoreRequest $request
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function store(CategoryStoreRequest $request)
{
Expand Down Expand Up @@ -78,9 +79,9 @@ public function store(CategoryStoreRequest $request)
* Show the form for editing the specified resource.
*
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
* @return \Illuminate\View\View
*/
public function edit(Category $category)
public function edit(Category $category): View
{
return view('admin.categories.save')->with([
'category' => $category,
Expand All @@ -93,7 +94,7 @@ public function edit(Category $category)
*
* @param \App\Requests\CategoryStoreRequest $request
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function update(CategoryStoreRequest $request, Category $category)
{
Expand Down Expand Up @@ -135,7 +136,7 @@ public function update(CategoryStoreRequest $request, Category $category)
* Remove the specified resource from storage.
*
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(Category $category)
{
Expand All @@ -148,7 +149,7 @@ public function destroy(Category $category)
*
* @param \App\Http\Requests\ImageRequest $request
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function updateImage(ImageRequest $request, Category $category)
{
Expand All @@ -162,7 +163,7 @@ public function updateImage(ImageRequest $request, Category $category)
* Remove the thumbnail from storage.
*
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function destroyImage(Category $category)
{
Expand Down
13 changes: 12 additions & 1 deletion app/Http/Controllers/Admin/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,27 @@
use App\Models\Post;
use App\Models\PostContent;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

class ContentController extends Controller
{
/**
* Delete content of category
*
* @param \App\Models\Content $content
* @return \Illuminate\Http\RedirectResponse
*/
public function deleteCategoryContent(Content $content)
{
$content->delete();
return redirect()->back()->withSuccess(__('This language data has been deleted.'));
}

/**
* Delete content of post
*
* @param \App\Models\PostContent $content
* @return \Illuminate\Http\RedirectResponse
*/
public function deletePostContent(PostContent $postContent)
{
$result = DB::select('select post_id from contents_of_posts where content_id = ?', [$postContent->id]);
Expand Down
25 changes: 13 additions & 12 deletions app/Http/Controllers/Admin/PostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Support\Facades\DB;
use Exception;
use Illuminate\Support\Facades\Log;
use Illuminate\View\View;

class PostsController extends Controller
{
Expand All @@ -23,9 +24,9 @@ class PostsController extends Controller
* Display a listing of the resource.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
* @return \Illuminate\View\View
*/
public function index(Request $request)
public function index(Request $request): View
{
$posts = Post::with(['author', 'categories', 'content'])->orderBy('id', 'desc')->search($request->q)->paginate(config('blog.pagination'))->withQueryString();
return view('admin.posts.index')->with([
Expand All @@ -37,9 +38,9 @@ public function index(Request $request)
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
* @return \Illuminate\View\View
*/
public function create()
public function create(): View
{
return view('admin.posts.save');
}
Expand All @@ -48,7 +49,7 @@ public function create()
* Store a newly created resource in storage.
*
* @param \App\Requests\PostStoreRequest $request
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function store(PostStoreRequest $request)
{
Expand Down Expand Up @@ -81,9 +82,9 @@ public function store(PostStoreRequest $request)
* Show the form for editing the specified resource.
*
* @param \App\Models\Post $post
* @return \Illuminate\Http\Response
* @return \Illuminate\View\View
*/
public function edit(Post $post)
public function edit(Post $post): View
{
if ($post->user_id == auth()->user()->id || auth()->user()->hasOneOfRoles(['admin', 'mod'])){
return view('admin.posts.save')->with([
Expand All @@ -99,7 +100,7 @@ public function edit(Post $post)
*
* @param \App\Requests\PostStoreRequest $request
* @param \App\Models\Post $post
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function update(PostStoreRequest $request, Post $post)
{
Expand Down Expand Up @@ -146,7 +147,7 @@ public function update(PostStoreRequest $request, Post $post)
* Remove the specified resource from storage.
*
* @param \App\Models\Post $post
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(Post $post)
{
Expand All @@ -162,7 +163,7 @@ public function destroy(Post $post)
*
* @param \App\Http\Requests\ImageRequest $request
* @param \App\Models\Post $post
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function updateImage(ImageRequest $request, Post $post)
{
Expand All @@ -179,7 +180,7 @@ public function updateImage(ImageRequest $request, Post $post)
* Remove the thumbnail from storage.
*
* @param \App\Models\Post $post
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function destroyImage(Post $post)
{
Expand Down Expand Up @@ -219,7 +220,7 @@ private function getValidatedData(PostStoreRequest $request): array
* @param \App\Models\Post $post
* @return void
*/
private function saveCategories(PostStoreRequest $request, Post $post)
private function saveCategories(PostStoreRequest $request, Post $post): void
{
DB::table('posts_of_categories')->where('post_id', '=', $post->id)->delete();
if (!empty($request->categories)){
Expand Down
18 changes: 12 additions & 6 deletions app/Http/Controllers/Admin/UserPanelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\Rule;
use Illuminate\View\View;

class UserPanelController extends Controller
{
public function index()
/**
* Handle the user panel view
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\View\View
*/
public function index(): View
{
return view('admin.user-panel.index')->with([
'user' => auth()->user(),
Expand All @@ -32,7 +39,7 @@ public function index()
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function update(Request $request)
{
Expand Down Expand Up @@ -60,7 +67,6 @@ public function update(Request $request)

DB::beginTransaction();
try {

$user->update([
'email' => $request->email,
'name' => $request->name,
Expand Down Expand Up @@ -93,7 +99,7 @@ public function update(Request $request)
* Update the password resource in storage.
*
* @param \App\Http\Requests\UserPasswordRequest $request
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function updatePassword(UserPasswordRequest $request)
{
Expand All @@ -108,7 +114,7 @@ public function updatePassword(UserPasswordRequest $request)
* Changes the thumbnail in storage.
*
* @param \App\Http\Requests\ImageRequest $request
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function updateImage(ImageRequest $request)
{
Expand All @@ -122,7 +128,7 @@ public function updateImage(ImageRequest $request)
/**
* Remove the thumbnail from storage.
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\RedirectResponse
*/
public function destroyImage()
{
Expand Down
Loading

0 comments on commit 79f5dc4

Please sign in to comment.