Langkah-langkah untuk menginstal Restful API Laravel 11 ini:
- Clone repositori ini.
git clone git@github.com:rizkijanuarr/laravel-11-api.git
- Masuk ke direktori proyek.
cd laravel-11-api
- Copy .env.example to .env
cp .env.example .env
- Install Composer.
composer install
- Generate App Key.
php artisan key:generate
- Konfigurasi Database on file .env
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel-11-api DB_USERNAME=root DB_PASSWORD=sesuaikan
- Storage link.
php artisan storage:link
- Migration ke Database.
php artisan migrate
- Jalankan web server.
php artisan serve
- http://127.0.0.1:8000/api/v1/posts || GET ✅
- http://127.0.0.1:8000/api/v1/posts || STORE ✅
- http://127.0.0.1:8000/api/v1/posts/1 || SHOW ✅
- http://127.0.0.1:8000/api/v1/posts/1 || UPDATE ✅
- http://127.0.0.1:8000/api/v1/posts/1 || DELETE ✅
-
GET
{ "success": true, "message": "List Data Posts", "data": { "current_page": 1, "data": [], "first_page_url": "http://127.0.0.1:8000/api/v1/posts?page=1", "from": null, "last_page": 1, "last_page_url": "http://127.0.0.1:8000/api/v1/posts?page=1", "links": [ { "url": null, "label": "« Previous", "active": false }, { "url": "http://127.0.0.1:8000/api/v1/posts?page=1", "label": "1", "active": true }, { "url": null, "label": "Next »", "active": false } ], "next_page_url": null, "path": "http://127.0.0.1:8000/api/v1/posts", "per_page": 5, "prev_page_url": null, "to": null, "total": 0 } }
-
STORE
Masuk ke dalam tab (Body) dan pilih (form-data)
KEY TYPE VALUE image file
Pilih gambar dari komputer title text
Citra Yudisium, yay! content text
Yayy, kerennn! { "success": true, "message": "Data Post Berhasil Ditambahkan!", "data": { "image": "http://127.0.0.1:8000/storage/posts/b20chVL3TBGoRVDHZNXFiqlenfrPH4tosA7TkPq7.png", "title": "Citra Yudisium, yay!", "content": "Yayyy kerennn!", "updated_at": "2024-06-25T08:14:50.000000Z", "created_at": "2024-06-25T08:14:50.000000Z", "id": 1 } }
-
SHOW
{ "success": true, "message": "Detail Data Post!", "data": { "id": 1, "image": "http://127.0.0.1:8000/storage/posts/b20chVL3TBGoRVDHZNXFiqlenfrPH4tosA7TkPq7.png", "title": "Citra Yudisium, yay!", "content": "Yayyy kerennn!", "created_at": "2024-06-25T08:14:50.000000Z", "updated_at": "2024-06-25T08:14:50.000000Z" } }
-
UPDATE
Masuk ke dalam tab (Body) dan pilih (form-data)
KEY TYPE VALUE image file
Pilih gambar dari komputer title text
Citra Yudisium, yay! - Update content text
Yayy, kerennn! - Update _method text
PUT { "success": true, "message": "Data Post Berhasil Diubah!", "data": { "id": 1, "image": "http://127.0.0.1:8000/storage/posts/b20chVL3TBGoRVDHZNXFiqlenfrPH4tosA7TkPq7.png", "title": "Citra Yudisium, yay! - Update", "content": "Yayyy kerennn! - Update", "created_at": "2024-06-25T08:14:50.000000Z", "updated_at": "2024-06-25T08:56:23.000000Z" } }
-
DELETE
{ "success": true, "message": "Data Post Berhasil Dihapus!", "data": null }
Jika Anda ingin menghubungi saya, Anda dapat mengirim email ke rzkjanuarr@gmail.com.