...
This commit is contained in:
parent
cedf373c03
commit
e225e05c52
21 changed files with 121 additions and 0 deletions
|
|
@ -26,5 +26,7 @@ Creates Controller, Model, Migration, Seeder
|
|||
|
||||
|
||||
```bash
|
||||
php spark migrate:status
|
||||
|
||||
php spark migrate
|
||||
```
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
https://www.youtube.com/watch?v=rlIKHZ5Nq2U&list=PLT9miexWCpPW6Z_OXNv2d78cqCrZaPrVG&index=14
|
||||
|
||||
app/Filters
|
||||
app/Config/Filters.php
|
||||
|
||||
![[Pasted image 20241116111944.png]]
|
||||
|
||||
```bash
|
||||
php spark make:filter Auth --suffix
|
||||
```
|
||||
![[Pasted image 20241116113439.png]]
|
||||
![[Pasted image 20241116113532.png]]
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
```bash
|
||||
php spark make:controller Api/Api --suffix --restful
|
||||
```
|
||||
|
||||
#17/38
|
||||
|
||||
== > Created controller ApiController (in Controlles subfolder Api) will have 9 methods.
|
||||
( WHich the tutorial doesnt use, basically only difference to standard Controllers is usage of ResourceController)
|
||||
|
||||
![[Pasted image 20241117112106.png]]
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
Routes.php
|
||||
![[Pasted image 20241117113037.png]]
|
||||
|
||||
Route parameter
|
||||
![[Pasted image 20241117113342.png]]
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
![[Pasted image 20241117113802.png]]
|
||||
|
||||
```php
|
||||
$studentObject = new StudentModel();
|
||||
|
||||
$imageFile = $this->request->getFile("profile_image");
|
||||
|
||||
// only go through image storing logic if image actually exists in payload
|
||||
if (isset($imageFile) && !empty($imageFile)) { // with image
|
||||
|
||||
$imageName = $imageFile->getName();
|
||||
$tempArray = explode(".", $imageName);
|
||||
$newImageName = round(microtime(true)) . "" . end($tempArray);
|
||||
|
||||
if($imageFile->move("images/" . $newImageName)) { // move automatically creates images folder if not exists
|
||||
$data = [
|
||||
"name" => $this->request->getVar("name"),
|
||||
"email" => $this->request->getVar("email"),
|
||||
"profile_image" => "images/" . $newImageName
|
||||
];
|
||||
}
|
||||
else {
|
||||
$response = [
|
||||
"status" => false,
|
||||
"message" => "Image Upload failed",
|
||||
"data" => []
|
||||
];
|
||||
}
|
||||
}
|
||||
else { // without image
|
||||
$data = [
|
||||
"name" => $this->request->getVar("name"),
|
||||
"email" => $this->request->getVar("email"),
|
||||
];
|
||||
}
|
||||
|
||||
// store student
|
||||
if ($studentObject->insert($data)) {
|
||||
$response = [
|
||||
"status" => true,
|
||||
"message" => "Student saved successfully",
|
||||
"data" => []
|
||||
];
|
||||
} else {
|
||||
$response = [
|
||||
"status" => false,
|
||||
"message" => "Failed to save student",
|
||||
"data" => []
|
||||
];
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue