...
This commit is contained in:
parent
d69b379f97
commit
37924f1187
3 changed files with 134 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
||||||
|
https://www.youtube.com/watch?v=B5GafCSXj9U&list=PLT9miexWCpPW6Z_OXNv2d78cqCrZaPrVG&index=37
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
https://www.youtube.com/watch?v=-NIoOj-FtHE&list=PLT9miexWCpPW6Z_OXNv2d78cqCrZaPrVG&index=36
|
||||||
|
|
||||||
|
ProjectController.php
|
||||||
|
```php
|
||||||
|
public function listProjects()
|
||||||
|
{
|
||||||
|
$user_id = auth()->id();
|
||||||
|
$pm = new ProjectModel();
|
||||||
|
|
||||||
|
$projectData = $pm->where([
|
||||||
|
"user_id" => $user_id
|
||||||
|
])->findAll();
|
||||||
|
|
||||||
|
if (count($projectData)>0) {
|
||||||
|
$response = [
|
||||||
|
"status" => true,
|
||||||
|
"message" => "Project data",
|
||||||
|
"data" => $projectData
|
||||||
|
];
|
||||||
|
}else {
|
||||||
|
$response = [
|
||||||
|
"status" => false,
|
||||||
|
"message" => "No Project data found",
|
||||||
|
"data" => []
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respondCreated($response);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Routes.php
|
||||||
|
```php
|
||||||
|
$routes->get("list-projects", "ProjectController::listProjects", ["filter" => "apiauth"]);
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
https://www.youtube.com/watch?v=B5GafCSXj9U&list=PLT9miexWCpPW6Z_OXNv2d78cqCrZaPrVG&index=37
|
||||||
|
|
||||||
|
ProjectController.php
|
||||||
|
```php
|
||||||
|
public function deleteProject($project_id)
|
||||||
|
{
|
||||||
|
$user_id = auth()->id();
|
||||||
|
if(!empty($project_id)) {
|
||||||
|
$pm = new ProjectModel();
|
||||||
|
$projectData = $pm->where([
|
||||||
|
"user_id" => $user_id,
|
||||||
|
"id" => $project_id
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
if (!empty($projectData)) {
|
||||||
|
if(pm->delete($project_id)) {
|
||||||
|
$response = [
|
||||||
|
"status" => true,
|
||||||
|
"message" => "project deleted",
|
||||||
|
"data" => []
|
||||||
|
];
|
||||||
|
}else {
|
||||||
|
$response = [
|
||||||
|
"status" => false,
|
||||||
|
"message" => "failed to delete project",
|
||||||
|
"data" => []
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$response = [
|
||||||
|
"status" => false,
|
||||||
|
"message" => "project not found",
|
||||||
|
"data" => []
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$response = [
|
||||||
|
"status" => false,
|
||||||
|
"message" => "Project Id required",
|
||||||
|
"data" => []
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respondCreated($response);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Routes.php
|
||||||
|
```php
|
||||||
|
$routes->delete("delete-project/(:num)", "ProjectController::deleteProject/$1",["filter"=>"apiauth"]);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Alternative version:
|
||||||
|
```php
|
||||||
|
public function deleteProject($project_id)
|
||||||
|
{
|
||||||
|
$user_id = auth()->id();
|
||||||
|
|
||||||
|
if(empty($project_id)) {
|
||||||
|
return $this->respondCreated([
|
||||||
|
"status" => false,
|
||||||
|
"message" => "project id required",
|
||||||
|
"data" => []
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pm = new ProjectModel();
|
||||||
|
$projectData = $pm->where([
|
||||||
|
"user_id" => $user_id,
|
||||||
|
"id" => $project_id
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
if(empty($projectData)) {
|
||||||
|
return $this->respondCreated([
|
||||||
|
"status" => false,
|
||||||
|
"message" => "project not found",
|
||||||
|
"data" => []
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$pm->delete($project_id)) {
|
||||||
|
return $this->respondCreated([
|
||||||
|
"status" => false,
|
||||||
|
"message" => "failed to delete project",
|
||||||
|
"data" => []
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respondCreated([
|
||||||
|
"status" => true,
|
||||||
|
"message" => "project deleted",
|
||||||
|
"data" => []
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
```
|
||||||
Loading…
Add table
Add a link
Reference in a new issue