Skip to content

Commit

Permalink
first test
Browse files Browse the repository at this point in the history
  • Loading branch information
victoredet committed Apr 13, 2023
1 parent ee97770 commit a552fa7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pet/app/Http/Controllers/PetController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PetController extends Controller
{
public $pets = ['dogs', 'cats', 'snakes', 'rabbits', 'gold fish'];

public function getAllPets()
{
$pets = $this->pets;
return $pets;
}
public function getSinglePet($id)
{
//check if index exists
$count = count($this->pets);
if ($id > $count) {
return response(['error' => 'this pet does not exist on our database'], 403); //'this pet does not exist on our database';
}
//return item
return $this->pets[$id];
}

public function addPet($id)
{
array_push($this->pets, $id);
return $this->pets;
}

public function removePet($id)
{
}
}
8 changes: 8 additions & 0 deletions pet/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PetController;

/*
|--------------------------------------------------------------------------
Expand All @@ -14,6 +15,13 @@
|
*/

Route::get('/', [PetController::class, 'getAllPets']);

Route::get('/add/{id}', [PetController::class, 'addPet']);

Route::get('/get_pet/{id}', [PetController::class, 'getSinglePet']);


Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});

0 comments on commit a552fa7

Please sign in to comment.