Skip to content

Commit bce472d

Browse files
committed
Clean code
1 parent 3167302 commit bce472d

15 files changed

+39
-50
lines changed

app/Constants/AuthConstants.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
class AuthConstants
66
{
7-
const VALIDATION = 'Email or Password wrong.';
8-
const UNAUTHORIZED = 'Unauthorized.';
9-
const REGISTER = 'User register successfully.';
10-
const LOGIN = 'User Login successfully.';
11-
const LOGOUT = 'User Logout successfully.';
12-
const PERMISSION = 'You don`t have permission.';
7+
public const VALIDATION = 'Email or Password wrong.';
8+
public const UNAUTHORIZED = 'Unauthorized.';
9+
public const REGISTER = 'User register successfully.';
10+
public const LOGIN = 'User Login successfully.';
11+
public const LOGOUT = 'User Logout successfully.';
12+
public const PERMISSION = 'You don`t have permission.';
1313
}

app/Constants/CategoryConstants.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class CategoryConstants
66
{
7-
const DESTROY = 'Category removed successfully.';
8-
const STORE = 'Category created successfully.';
9-
const UPDATE = 'Category updated successfully.';
7+
public const DESTROY = 'Category removed successfully.';
8+
public const STORE = 'Category created successfully.';
9+
public const UPDATE = 'Category updated successfully.';
1010
}

app/Constants/ProductConstants.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ProductConstants
66
{
7-
const DESTROY = 'Product removed successfully.';
8-
const STORE = 'Product created successfully.';
9-
const UPDATE = 'Product updated successfully.';
7+
public const DESTROY = 'Product removed successfully.';
8+
public const STORE = 'Product created successfully.';
9+
public const UPDATE = 'Product updated successfully.';
1010
}

app/Constants/ValidationConstants.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
class ValidationConstants
66
{
7-
const ERROR = 'Validation errors.';
7+
public const ERROR = 'Validation errors.';
88
}

app/Events/UserRegistered.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
namespace App\Events;
44

55
use App\Models\User;
6-
use Illuminate\Broadcasting\Channel;
76
use Illuminate\Broadcasting\InteractsWithSockets;
8-
use Illuminate\Broadcasting\PresenceChannel;
9-
use Illuminate\Broadcasting\PrivateChannel;
10-
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
117
use Illuminate\Foundation\Events\Dispatchable;
128
use Illuminate\Queue\SerializesModels;
139

1410
class UserRegistered
1511
{
16-
use Dispatchable, InteractsWithSockets, SerializesModels;
12+
use Dispatchable;
13+
use InteractsWithSockets;
14+
use SerializesModels;
1715

1816
/**
1917
* @var User

app/Http/Controllers/API/Auth/LoginController.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace App\Http\Controllers\API\Auth;
44

5-
use App\Http\Requests\AuthRequest;
6-
use Illuminate\Http\JsonResponse;
7-
use Illuminate\Support\Facades\Auth;
85
use App\Constants\AuthConstants;
96
use App\Http\Controllers\Controller;
7+
use App\Http\Requests\AuthRequest;
108
use App\Http\Traits\HttpResponses;
9+
use Illuminate\Http\JsonResponse;
10+
use Illuminate\Support\Facades\Auth;
1111

1212
class LoginController extends Controller
1313
{

app/Http/Controllers/API/Auth/RegisterController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace App\Http\Controllers\API\Auth;
44

5-
use App\Http\Requests\RegisterRequest;
65
use App\Constants\AuthConstants;
76
use App\Events\UserRegistered;
87
use App\Http\Controllers\Controller;
8+
use App\Http\Requests\RegisterRequest;
99
use App\Http\Traits\HttpResponses;
1010
use App\Models\User;
1111
use Illuminate\Http\JsonResponse;

app/Http/Controllers/API/CategoryController.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
namespace App\Http\Controllers\API;
44

5-
use App\Models\Category;
6-
use Illuminate\Http\JsonResponse;
75
use App\Constants\AuthConstants;
86
use App\Constants\CategoryConstants;
97
use App\Http\Controllers\Controller;
108
use App\Http\Requests\CategoryRequest;
119
use App\Http\Resources\CategoryResource;
1210
use App\Http\Traits\Access;
1311
use App\Http\Traits\HttpResponses;
12+
use App\Models\Category;
13+
use Illuminate\Http\JsonResponse;
1414

1515
class CategoryController extends Controller
1616
{
17-
use HttpResponses, Access;
17+
use Access;
18+
use HttpResponses;
1819

1920
/**
2021
* @return JsonResponse

app/Http/Controllers/API/ProductController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
use App\Constants\ProductConstants;
77
use App\Http\Controllers\Controller;
88
use App\Http\Requests\ProductRequest;
9-
use App\Http\Traits\HttpResponses;
109
use App\Http\Resources\ProductResource;
1110
use App\Http\Traits\Access;
11+
use App\Http\Traits\HttpResponses;
1212
use App\Models\Category;
1313
use App\Models\Product;
1414
use Illuminate\Http\JsonResponse;
1515

1616
class ProductController extends Controller
1717
{
18-
use HttpResponses, Access;
18+
use Access;
19+
use HttpResponses;
1920

2021
/**
2122
* @return JsonResponse

app/Http/Traits/Access.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace App\Http\Traits;
44

5-
use Illuminate\Support\Facades\Auth;
65
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Support\Facades\Auth;
77

88
trait Access
99
{
1010
/**
1111
* @param Model $model
12-
* @return boolean
12+
* @return bool
1313
*/
1414
protected function canAccess(Model $model): bool
1515
{

app/Jobs/UserRegisteredEmailJob.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44

55
use App\Models\User;
66
use Illuminate\Bus\Queueable;
7-
use Illuminate\Contracts\Queue\ShouldBeUnique;
87
use Illuminate\Contracts\Queue\ShouldQueue;
98
use Illuminate\Foundation\Bus\Dispatchable;
109
use Illuminate\Queue\InteractsWithQueue;
1110
use Illuminate\Queue\SerializesModels;
12-
use Illuminate\Support\Facades\Log;
1311

1412
class UserRegisteredEmailJob implements ShouldQueue
1513
{
16-
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
14+
use Dispatchable;
15+
use InteractsWithQueue;
16+
use Queueable;
17+
use SerializesModels;
1718

1819
/**
1920
* @var User

app/Listeners/UserRegisteredEmailNotification.php

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use App\Events\UserRegistered;
66
use App\Jobs\UserRegisteredEmailJob;
77
use Illuminate\Contracts\Queue\ShouldQueue;
8-
use Illuminate\Queue\InteractsWithQueue;
98

109
class UserRegisteredEmailNotification implements ShouldQueue
1110
{

app/Models/Category.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace App\Models;
44

5-
use Illuminate\Database\Eloquent\Factories\HasFactory;
6-
use Illuminate\Database\Eloquent\Model;
75
use Illuminate\Database\Eloquent\Builder;
86
use Illuminate\Database\Eloquent\Collection;
7+
use Illuminate\Database\Eloquent\Factories\HasFactory;
8+
use Illuminate\Database\Eloquent\Model;
99
use Illuminate\Database\Eloquent\Relations\BelongsTo;
1010
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
1111
use Illuminate\Support\Facades\Auth;

app/Models/User.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44

55
// use Illuminate\Contracts\Auth\MustVerifyEmail;
66
use Illuminate\Database\Eloquent\Factories\HasFactory;
7+
use Illuminate\Database\Eloquent\Relations\HasMany;
78
use Illuminate\Foundation\Auth\User as Authenticatable;
89
use Illuminate\Notifications\Notifiable;
910
use Laravel\Sanctum\HasApiTokens;
10-
use Illuminate\Database\Eloquent\Relations\HasMany;
1111

1212
class User extends Authenticatable
1313
{
14-
use HasApiTokens, HasFactory, Notifiable;
14+
use HasApiTokens;
15+
use HasFactory;
16+
use Notifiable;
1517

1618
/**
1719
* The attributes that are mass assignable.

routes/api.php

-13
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,8 @@
44
use App\Http\Controllers\API\Auth\RegisterController;
55
use App\Http\Controllers\API\CategoryController;
66
use App\Http\Controllers\API\ProductController;
7-
use Illuminate\Http\Request;
87
use Illuminate\Support\Facades\Route;
98

10-
/*
11-
|--------------------------------------------------------------------------
12-
| API Routes
13-
|--------------------------------------------------------------------------
14-
|
15-
| Here is where you can register API routes for your application. These
16-
| routes are loaded by the RouteServiceProvider and all of them will
17-
| be assigned to the "api" middleware group. Make something great!
18-
|
19-
*/
20-
21-
229
Route::post('login', [LoginController::class, 'login']);
2310
Route::post('register', RegisterController::class);
2411

0 commit comments

Comments
 (0)