diff --git a/.env.example b/.env.example deleted file mode 100644 index b7becba..0000000 --- a/.env.example +++ /dev/null @@ -1,52 +0,0 @@ -APP_NAME=Laravel -APP_ENV=local -APP_KEY= -APP_DEBUG=true -APP_URL=http://localhost - -LOG_CHANNEL=stack -LOG_DEPRECATIONS_CHANNEL=null -LOG_LEVEL=debug - -DB_CONNECTION=mysql -DB_HOST=127.0.0.1 -DB_PORT=3306 -DB_DATABASE=laravel -DB_USERNAME=root -DB_PASSWORD= - -BROADCAST_DRIVER=log -CACHE_DRIVER=file -FILESYSTEM_DRIVER=local -QUEUE_CONNECTION=sync -SESSION_DRIVER=file -SESSION_LIFETIME=120 - -MEMCACHED_HOST=127.0.0.1 - -REDIS_HOST=127.0.0.1 -REDIS_PASSWORD=null -REDIS_PORT=6379 - -MAIL_MAILER=smtp -MAIL_HOST=mailhog -MAIL_PORT=1025 -MAIL_USERNAME=null -MAIL_PASSWORD=null -MAIL_ENCRYPTION=null -MAIL_FROM_ADDRESS=null -MAIL_FROM_NAME="${APP_NAME}" - -AWS_ACCESS_KEY_ID= -AWS_SECRET_ACCESS_KEY= -AWS_DEFAULT_REGION=us-east-1 -AWS_BUCKET= -AWS_USE_PATH_STYLE_ENDPOINT=false - -PUSHER_APP_ID= -PUSHER_APP_KEY= -PUSHER_APP_SECRET= -PUSHER_APP_CLUSTER=mt1 - -MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" -MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php new file mode 100644 index 0000000..e7e9217 --- /dev/null +++ b/app/Http/Controllers/ProjectController.php @@ -0,0 +1,117 @@ +middleware('auth:api', ['except' => ['indexAll']]); + $this->projectRepository = $projectRepository; + } + + public function index(): JsonResponse + { + try { + $data = $this->projectRepository->getAll(); + return $this->responseSuccess($data, 'Project List Fetch Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + public function indexAll(Request $request): JsonResponse + { + try { + $data = $this->projectRepository->getPaginatedData($request->perPage); + return $this->responseSuccess($data, 'Project List Fetched Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + public function search(Request $request): JsonResponse + { + try { + $data = $this->projectRepository->searchProject($request->search, $request->perPage); + return $this->responseSuccess($data, 'Project List Fetched Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + public function store(ProjectRequest $request): JsonResponse + { + try { + $project = $this->projectRepository->create($request->all()); + return $this->responseSuccess($project, 'New Project Created Successfully !'); + } catch (\Exception $exception) { + return $this->responseError(null, $exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + public function show($id): JsonResponse + { + try { + $data = $this->projectRepository->getByID($id); + if (is_null($data)) { + return $this->responseError(null, 'Project Not Found', Response::HTTP_NOT_FOUND); + } + + return $this->responseSuccess($data, 'Project Details Fetch Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + public function update(ProjectRequest $request, $id): JsonResponse + { + try { + $data = $this->projectRepository->update($id, $request->all()); + if (is_null($data)) + return $this->responseError(null, 'Project Not Found', Response::HTTP_NOT_FOUND); + + return $this->responseSuccess($data, 'Project Updated Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + public function destroy($id): JsonResponse + { + try { + $project = $this->projectRepository->getByID($id); + if (empty($project)) { + return $this->responseError(null, 'Project Not Found', Response::HTTP_NOT_FOUND); + } + + $deleted = $this->projectRepository->delete($id); + if (!$deleted) { + return $this->responseError(null, 'Failed to delete the project.', Response::HTTP_INTERNAL_SERVER_ERROR); + } + + return $this->responseSuccess($project, 'Project Deleted Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } +} \ No newline at end of file diff --git a/app/Http/Controllers/TaskController.php b/app/Http/Controllers/TaskController.php new file mode 100644 index 0000000..ad5e9ce --- /dev/null +++ b/app/Http/Controllers/TaskController.php @@ -0,0 +1,117 @@ +middleware('auth:api', ['except' => ['indexAll']]); + $this->taskRepository = $taskRepository; + } + + public function index(): JsonResponse + { + try { + $data = $this->taskRepository->getAll(); + return $this->responseSuccess($data, 'Task List Fetch Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + public function indexAll(Request $request): JsonResponse + { + try { + $data = $this->taskRepository->getPaginatedData($request->perPage); + return $this->responseSuccess($data, 'Task List Fetched Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + public function search(Request $request): JsonResponse + { + try { + $data = $this->taskRepository->searchTask($request->search, $request->perPage); + return $this->responseSuccess($data, 'Task List Fetched Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + public function store(TaskRequest $request): JsonResponse + { + try { + $task = $this->taskRepository->create($request->all()); + return $this->responseSuccess($task, 'New Task Created Successfully !'); + } catch (\Exception $exception) { + return $this->responseError(null, $exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + public function show($id): JsonResponse + { + try { + $data = $this->taskRepository->getByID($id); + if (is_null($data)) { + return $this->responseError(null, 'Task Not Found', Response::HTTP_NOT_FOUND); + } + + return $this->responseSuccess($data, 'Task Details Fetch Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + public function update(TaskRequest $request, $id): JsonResponse + { + try { + $data = $this->taskRepository->update($id, $request->all()); + if (is_null($data)) + return $this->responseError(null, 'Task Not Found', Response::HTTP_NOT_FOUND); + + return $this->responseSuccess($data, 'Task Updated Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + public function destroy($id): JsonResponse + { + try { + $task = $this->taskRepository->getByID($id); + if (empty($task)) { + return $this->responseError(null, 'Task Not Found', Response::HTTP_NOT_FOUND); + } + + $deleted = $this->taskRepository->delete($id); + if (!$deleted) { + return $this->responseError(null, 'Failed to delete the task.', Response::HTTP_INTERNAL_SERVER_ERROR); + } + + return $this->responseSuccess($task, 'Task Deleted Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } +} \ No newline at end of file diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php new file mode 100644 index 0000000..8f005bb --- /dev/null +++ b/app/Http/Controllers/UserController.php @@ -0,0 +1,117 @@ +middleware('auth:api', ['except' => ['login', 'register']]); + $this->userRepository = $ar; + } + + public function index(): JsonResponse + { + try { + $data = $this->userRepository->getAll(); + return $this->responseSuccess($data, 'User List Fetch Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + public function store(UserRequest $request): JsonResponse + { + try { + $user = $this->userRepository->create($request->all()); + return $this->responseSuccess($user, 'New User Created Successfully !'); + } catch (\Exception $exception) { + return $this->responseError(null, $exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + + public function show($id): JsonResponse + { + try { + $data = $this->userRepository->getByID($id); + if (is_null($data)) { + return $this->responseError(null, 'User Not Found', Response::HTTP_NOT_FOUND); + } + + return $this->responseSuccess($data, 'User Details Fetch Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + public function update(UserRequest $request, $id): JsonResponse + { + try { + $data = $this->userRepository->update($id, $request->all()); + if (is_null($data)) + return $this->responseError(null, 'User Not Found', Response::HTTP_NOT_FOUND); + + return $this->responseSuccess($data, 'User Updated Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + public function destroy($id): JsonResponse + { + try { + $user = $this->userRepository->getByID($id); + if (empty($user)) { + return $this->responseError(null, 'User Not Found', Response::HTTP_NOT_FOUND); + } + + $deleted = $this->userRepository->delete($id); + if (!$deleted) { + return $this->responseError(null, 'Failed to delete the user.', Response::HTTP_INTERNAL_SERVER_ERROR); + } + + return $this->responseSuccess($user, 'User Deleted Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + + + + public function me(): JsonResponse + { + try { + $data = $this->guard()->user(); + return $this->responseSuccess($data, 'Profile Fetched Successfully !'); + } catch (\Exception $e) { + return $this->responseError(null, $e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR); + } + } + +} \ No newline at end of file diff --git a/app/Http/Requests/FormRequest.php b/app/Http/Requests/FormRequest.php new file mode 100644 index 0000000..2afea29 --- /dev/null +++ b/app/Http/Requests/FormRequest.php @@ -0,0 +1,48 @@ +errors(); + + throw new HttpResponseException( + $this->responseError($errors) + ); + } +} \ No newline at end of file diff --git a/app/Http/Requests/ProjectRequest.php b/app/Http/Requests/ProjectRequest.php new file mode 100644 index 0000000..bd03df9 --- /dev/null +++ b/app/Http/Requests/ProjectRequest.php @@ -0,0 +1,40 @@ + 'required|string|regex:/\w*$/|max:255|unique:project,name', + ]; + } + + /** + * Determine if the project is authorized to make this request. + * + * @return bool + */ + public function authorize(): bool + { + return true; + } + + /** + * @return array + * Custom validation message + */ + public function messages(): array + { + return [ + 'name.required' => 'Please give project name', + 'name.max' => 'Please give name name maximum of 255 characters', + ]; + } +} \ No newline at end of file diff --git a/app/Http/Requests/TaskRequest.php b/app/Http/Requests/TaskRequest.php new file mode 100644 index 0000000..72e32dc --- /dev/null +++ b/app/Http/Requests/TaskRequest.php @@ -0,0 +1,46 @@ + 'required|max:255', + 'description' => 'nullable|max:255', + 'status' => 'required|max:255', + // 'project_id' => 'required|max:255', + // 'user_id' => 'required|max:255', + ]; + } + + /** + * Determine if the project is authorized to make this request. + * + * @return bool + */ + public function authorize(): bool + { + return true; + } + + /** + * @return array + * Custom validation message + */ + public function messages(): array + { + return [ + 'title.required' => 'Please give task title', + 'title.max' => 'Please give task title maximum of 255 characters', + 'description.max' => 'Please give task description maximum of 5000 characters', + 'status.required' => 'Please give task status', + ]; + } +} \ No newline at end of file diff --git a/app/Http/Requests/UserRequest.php b/app/Http/Requests/UserRequest.php new file mode 100644 index 0000000..faa42b1 --- /dev/null +++ b/app/Http/Requests/UserRequest.php @@ -0,0 +1,54 @@ + 'required|max:255', + 'username' => 'required|string|regex:/\w*$/|max:255|unique:users,username', // 'required|max:255', + 'password' => [ + 'required', + 'string', + 'min:6', // must be at least 10 characters in length + 'regex:/[a-z]/', // must contain at least one lowercase letter + 'regex:/[A-Z]/', // must contain at least one uppercase letter + 'regex:/[0-9]/', // must contain at least one digit + 'regex:/[@$!%*#?&]/', // must contain a special character + ], + ]; + } + + /** + * Determine if the user is authorized to make this request. + * + * @return bool + */ + public function authorize(): bool + { + return true; + } + + /** + * @return array + * Custom validation message + */ + public function messages(): array + { + return [ + 'name.required' => 'Please give user name', + 'name.max' => 'Please give user name maximum of 255 characters', + 'username.required' => 'Please give user username', + 'username.unique' => 'Please give user unique username', + 'password.required' => 'Please give user password', + 'password.min' => 'Please give user password minimum of 6 characters' + ]; + } +} \ No newline at end of file diff --git a/app/Interfaces/CrudInterface.php b/app/Interfaces/CrudInterface.php new file mode 100644 index 0000000..7b0c8fd --- /dev/null +++ b/app/Interfaces/CrudInterface.php @@ -0,0 +1,54 @@ +hasMany(Project::class)->orderBy('id', 'desc'); + } + +} diff --git a/app/Models/Task.php b/app/Models/Task.php new file mode 100644 index 0000000..0a37363 --- /dev/null +++ b/app/Models/Task.php @@ -0,0 +1,35 @@ +belongsTo(User::class)->select('id', 'name', 'username'); + } + public function project(): object + { + return $this->belongsTo(Project::class)->select('id', 'name'); + } + +} diff --git a/app/Models/User.php b/app/Models/User.php index 8996368..6707f22 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -19,7 +19,7 @@ class User extends Authenticatable */ protected $fillable = [ 'name', - 'email', + 'username', 'password', ]; @@ -34,11 +34,16 @@ class User extends Authenticatable ]; /** - * The attributes that should be cast. + * Tasks * - * @var array + * Get All Tasks uploaded by user + * + * @return object Eloquent task object */ - protected $casts = [ - 'email_verified_at' => 'datetime', - ]; + + public function tasks() + { + return $this->hasMany(Task::class)->orderBy('id', 'desc'); + } + } diff --git a/app/Repositories/ProjectRepository.php b/app/Repositories/ProjectRepository.php new file mode 100644 index 0000000..063ac30 --- /dev/null +++ b/app/Repositories/ProjectRepository.php @@ -0,0 +1,131 @@ +user = Auth::guard()->user(); + } + + /** + * Get All Projects. + * + * @return collections Array of Project Collection + */ + public function getAll(): Paginator + { + return Project::orderBy('id', 'desc') + ->paginate(10); + } + + /** + * Get Paginated Project Data. + * + * @param int $pageNo + * @return collections Array of Project Collection + */ + public function getPaginatedData($perPage): Paginator + { + $perPage = isset($perPage) ? intval($perPage) : 12; + return Project::orderBy('id', 'desc') + ->paginate($perPage); + } + + /** + * Get Searchable Project Data with Pagination. + * + * @param int $pageNo + * @return collections Array of Project Collection + */ + public function searchProject($keyword, $perPage): Paginator + { + $perPage = isset($perPage) ? intval($perPage) : 10; + + return Project::where('title', 'like', '%' . $keyword . '%') + ->orWhere('description', 'like', '%' . $keyword . '%') + ->orWhere('price', 'like', '%' . $keyword . '%') + ->orderBy('id', 'desc') + ->paginate($perPage); + } + + /** + * Create New Project. + * + * @param array $data + * @return object Project Object + */ + public function create(array $data): Project + { + return Project::create($data); + } + + /** + * Delete Project. + * + * @param int $id + * @return boolean true if deleted otherwise false + */ + public function delete(int $id): bool + { + $project = Project::find($id); + if (empty($project)) { + return false; + } + $project->delete($project); + return true; + } + + /** + * Get Project Detail By ID. + * + * @param int $id + * @return void + */ + public function getByID(int $id): Project + { + return Project::findOrFail($id); + } + + /** + * Update Project By ID. + * + * @param int $id + * @param array $data + * @return object Updated Project Object + */ + public function update(int $id, array $data): Project + { + $project = Project::find($id); + + if (is_null($project)) { + return null; + } + + // If everything is OK, then update. + $project->update($data); + + // Finally return the updated project. + return $this->getByID($project->id); + } +} \ No newline at end of file diff --git a/app/Repositories/TaskRepository.php b/app/Repositories/TaskRepository.php new file mode 100644 index 0000000..52720c6 --- /dev/null +++ b/app/Repositories/TaskRepository.php @@ -0,0 +1,139 @@ +user = Auth::guard()->user(); + } + + /** + * Get All Tasks. + * + * @return collections Array of Task Collection + */ + public function getAll(): Paginator + { + return Task::orderBy('id', 'desc') + ->with('user') + ->with('project') + ->paginate(10); + } + + /** + * Get Paginated Task Data. + * + * @param int $pageNo + * @return collections Array of Task Collection + */ + public function getPaginatedData($perPage): Paginator + { + $perPage = isset($perPage) ? intval($perPage) : 12; + return Task::orderBy('id', 'desc') + ->with('user') + ->with('project') + ->paginate($perPage); + } + + /** + * Get Searchable Task Data with Pagination. + * + * @param int $pageNo + * @return collections Array of Task Collection + */ + public function searchTask($keyword, $perPage): Paginator + { + $perPage = isset($perPage) ? intval($perPage) : 10; + + return Task::where('title', 'like', '%' . $keyword . '%') + ->orWhere('description', 'like', '%' . $keyword . '%') + ->orWhere('price', 'like', '%' . $keyword . '%') + ->orderBy('id', 'desc') + ->with('user') + ->paginate($perPage); + } + + /** + * Create New Task. + * + * @param array $data + * @return object Task Object + */ + public function create(array $data): Task + { + // $data['user_id'] = $this->user->id; + + return Task::create($data); + } + + /** + * Delete Task. + * + * @param int $id + * @return boolean true if deleted otherwise false + */ + public function delete(int $id): bool + { + $product = Task::find($id); + if (empty($product)) { + return false; + } + $product->delete($product); + return true; + } + + /** + * Get Task Detail By ID. + * + * @param int $id + * @return void + */ + public function getByID(int $id): Task + { + return Task::with('user')->with('project')->find($id); + } + + /** + * Update Task By ID. + * + * @param int $id + * @param array $data + * @return object Updated Task Object + */ + public function update(int $id, array $data): Task + { + $product = Task::find($id); + if (is_null($product)) { + return null; + } + + // If everything is OK, then update. + $product->update($data); + + // Finally return the updated product. + return $this->getByID($product->id); + } +} \ No newline at end of file diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php new file mode 100644 index 0000000..6505f3a --- /dev/null +++ b/app/Repositories/UserRepository.php @@ -0,0 +1,136 @@ +user = Auth::guard()->user(); + } + + /** + * Get All Users. + * + * @return collections Array of User Collection + */ + public function getAll(): Paginator + { + return User::orderBy('id', 'desc') + ->paginate(10); + } + + + /** + * Get Paginated User Data. + * + * @param int $pageNo + * @return collections Array of User Collection + */ + public function getPaginatedData($perPage): Paginator + { + $perPage = isset($perPage) ? intval($perPage) : 12; + return User::orderBy('id', 'desc') + ->with('user') + ->paginate($perPage); + } + + /** + * Create New User. + * + * @param array $data + * @return object User Object + */ + public function create(array $data): User + { + + $data = [ + 'name' => $data['name'], + 'username' => $data['username'], + 'password' => Hash::make($data['password']) + ]; + + return User::create($data); + } + + /** + * Delete User. + * + * @param int $id + * @return boolean true if deleted otherwise false + */ + public function delete(int $id): bool + { + $user = User::find($id); + if (empty($user)) { + return false; + } + $user->delete($user); + return true; + } + + /** + * Get User Detail By ID. + * + * @param int $id + * @return void + */ + public function getByID(int $id): User + { + return User::findOrFail($id); + } + + /** + * Update User By ID. + * + * @param int $id + * @param array $data + * @return object Updated User Object + */ + public function update(int $id, array $data): User + { + $user = User::find($id); + if (!empty($data['image'])) { + $titleShort = Str::slug(substr($data['title'], 0, 20)); + $data['image'] = UploadHelper::update('image', $data['image'], $titleShort . '-' . time(), 'images/users', $user->image); + } else { + $data['image'] = $user->image; + } + + if (is_null($user)) { + return null; + } + + // If everything is OK, then update. + $user->update($data); + + // Finally return the updated user. + return $this->getByID($user->id); + } + + + + public function register(array $data): User + { + $data = [ + 'name' => $data['name'], + 'username' => $data['username'], + 'password' => Hash::make($data['password']) + ]; + + return User::create($data); + } +} \ No newline at end of file diff --git a/app/Traits/ResponseTrait.php b/app/Traits/ResponseTrait.php new file mode 100644 index 0000000..f1b7894 --- /dev/null +++ b/app/Traits/ResponseTrait.php @@ -0,0 +1,46 @@ +json([ + 'status' => true, + 'message' => $message, + 'errors' => null, + 'data' => $data, + ], $status_code); + } + + /** + * Generate Error response. + * + * Returns the errors data if there is any error + * + * @param object $errors + * @return JsonResponse + */ + public function responseError($errors, $message = 'Data is invalid', $status_code = JsonResponse::HTTP_BAD_REQUEST): JsonResponse + { + return response()->json([ + 'status' => false, + 'message' => $message, + 'errors' => $errors, + 'data' => null, + ], $status_code); + } +} \ No newline at end of file diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 621a24e..e1ced80 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -16,8 +16,7 @@ public function up() Schema::create('users', function (Blueprint $table) { $table->id(); $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); + $table->string('username')->unique(); $table->string('password'); $table->rememberToken(); $table->timestamps(); diff --git a/database/migrations/2023_04_23_172922_create_project_table.php b/database/migrations/2023_04_23_172922_create_project_table.php new file mode 100644 index 0000000..268229c --- /dev/null +++ b/database/migrations/2023_04_23_172922_create_project_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('name')->unique(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('project'); + } +} diff --git a/database/migrations/2023_04_23_172958_create_task_table.php b/database/migrations/2023_04_23_172958_create_task_table.php new file mode 100644 index 0000000..39bdacb --- /dev/null +++ b/database/migrations/2023_04_23_172958_create_task_table.php @@ -0,0 +1,38 @@ +id(); + $table->string('title'); + $table->string('description'); + $table->string('status'); + $table->unsignedBigInteger('project_id'); + $table->unsignedBigInteger('user_id'); + $table->foreign('project_id')->references('id')->on('project'); + $table->foreign('user_id')->references('id')->on('users'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('task'); + } +} diff --git a/routes/api.php b/routes/api.php index eb6fa48..a8297ea 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,8 +1,10 @@ get('/user', function (Request $request) { return $request->user(); }); + +Route::group([ + 'middleware' => 'api' +], function ($router) { + + + /** User Module*/ + Route::resource('users', UserController::class); + + /** Project Module*/ + Route::resource('projects', ProjectController::class); + + /** Task Module*/ + Route::resource('tasks', TaskController::class); + + + /** + * Products Module + */ + // Route::resource('products', ProductsController::class); + // Route::resource('products', ProductsController::class); + // Route::get('products/view/all', [ProductsController::class, 'indexAll']); + // Route::get('products/view/search', [ProductsController::class, 'search']); + +}); \ No newline at end of file