Skip to content

Commit

Permalink
Some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Freddiefady committed Jan 27, 2025
1 parent b3a03c3 commit 7c0bbda
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions app/Http/Controllers/Api/Auth/Account/PostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public function index()
}

$posts = $user->posts()->active()->activeCategory()->get();
if (!$posts) {
return responseApi(null, 'No posts found.', 404);
if ($posts->count() > 0) {
return responseApi(new PostsCollection($posts), 'Response posts data successfully', 200);
}
return responseApi(new PostsCollection($posts), 'Response posts data successfully', 200);
return responseApi(null, 'No posts found.', 404);
}
public function store(PostRequest $request)
{
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Api/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function getSettings()
{
$settings = Setting::first();
if(!$settings){
return responseApi(new SettingsResoucres($settings), 'Not found Settings', 404);
return responseApi(null, 'Not found Settings', 404);
}
$data = [
'settings' => new SettingsResoucres($settings),
Expand All @@ -26,8 +26,8 @@ public function relatedNews()
{
$related = RelatedNewsSite::select('name', 'url')->get();
if(!$related){
return responseApi($related, 'Not found related', 404);
return responseApi(null, 'Not found related', 404);
}
return responseApi(['related-news'=>$related], 'Response data successfully', 200);
return $related;
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Dashboard/Admins/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public function update(AdminsRequest $request, string $id)
public function destroy(string $id)
{
$admin = Admin::findOrFail($id);
$admin->delete();
if(!$admin)
{
return redirect()->back()->with('error', 'Invalid Try again');
}
$admin->delete();
Session::flash('success', 'Deleted Successfully');
return redirect()->back();
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Dashboard/Posts/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function imageDestroy(Request $request, $image_id)
if (!$image)
{
return response()->json([
'status'=>201,
'status'=>404,
'msg'=>'Image Not Found',
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function index()
}
public function show()
{
auth()->user()->unreadNotifications->markAsRead();
Session::flash('success', 'Notification has been marked as read');
return redirect()->back();
auth()->user()->unreadNotifications->markAsRead();
Session::flash('success', 'Notification has been marked as read');
return redirect()->back();
}
public function destroyAll()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function imageDestroy(Request $request, $image_id)
if (!$image)
{
return response()->json([
'status'=>201,
'status'=>404,
'msg'=>'Image Not Found',
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function update(UserSettingsRequest $request)
$request->validated();
// code to update user settings goes here
$user = User::findOrFail(auth()->user()->id);
$user->update($request->except(['_token, image']));
$user->update($request->except(['_token','image']));
ImageManager::UploadImages($request, $user, null);

return redirect()->back()->with('success', 'User settings updated successfully');
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/PostsResoucre.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PostsResoucre extends JsonResource
*/
public function toArray(Request $request): array
{
$data = [
$data = [
'id' => $this->id,
'title'=>$this->title,
'slug'=>$this->slug,
Expand Down
18 changes: 9 additions & 9 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php

use App\Http\Controllers\Api\Auth\Account\NotificationsContoller;
use App\Http\Controllers\Api\Auth\Account\PostsController;
use App\Http\Controllers\Api\Auth\Account\ProfileController;
use App\Http\Controllers\Api\Auth\EmailVerifyController;
use App\Http\Controllers\Api\Auth\LoginController;
use App\Http\Controllers\Api\Auth\password\ForgetPasswordController;
use App\Http\Controllers\Api\Auth\password\ResetPasswordController;
use App\Http\Controllers\Api\Auth\RegistrationController;
use Illuminate\Http\Request;
use App\Http\Resources\UserResource;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\ContactController;
use App\Http\Controllers\Api\GeneralController;
use App\Http\Controllers\Api\CategoryController;
use App\Http\Controllers\Api\SettingsController;
use App\Http\Resources\UserResource;
use App\Http\Controllers\Api\Auth\LoginController;
use App\Http\Controllers\Api\Auth\EmailVerifyController;
use App\Http\Controllers\Api\Auth\RegistrationController;
use App\Http\Controllers\Api\Auth\Account\PostsController;
use App\Http\Controllers\Api\Auth\Account\ProfileController;
use App\Http\Controllers\Api\Auth\Account\NotificationsContoller;
use App\Http\Controllers\Api\Auth\password\ResetPasswordController;
use App\Http\Controllers\Api\Auth\password\ForgetPasswordController;

/*
|--------------------------------------------------------------------------
Expand Down

0 comments on commit 7c0bbda

Please sign in to comment.