{"id":15594512,"url":"https://github.com/caknoooo/simple_accountancy_restapi","last_synced_at":"2026-05-19T04:05:17.655Z","repository":{"id":141373998,"uuid":"581762192","full_name":"Caknoooo/Simple_Accountancy_RestAPI","owner":"Caknoooo","description":"This repository uses the simple framework of Laravel, and rest-API. It is the result of a study though with the help of youtube ^-^","archived":false,"fork":false,"pushed_at":"2022-12-24T13:21:42.000Z","size":81,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-04T09:34:01.153Z","etag":null,"topics":["accounting","laravel","rest-api"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Caknoooo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-24T08:24:05.000Z","updated_at":"2023-02-06T06:33:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"2d864eb4-f506-42d5-8838-7182955c7161","html_url":"https://github.com/Caknoooo/Simple_Accountancy_RestAPI","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caknoooo%2FSimple_Accountancy_RestAPI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caknoooo%2FSimple_Accountancy_RestAPI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caknoooo%2FSimple_Accountancy_RestAPI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caknoooo%2FSimple_Accountancy_RestAPI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Caknoooo","download_url":"https://codeload.github.com/Caknoooo/Simple_Accountancy_RestAPI/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246174498,"owners_count":20735412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["accounting","laravel","rest-api"],"created_at":"2024-10-03T00:40:49.886Z","updated_at":"2026-05-19T04:05:12.585Z","avatar_url":"https://github.com/Caknoooo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel 8 learning outcomes\n\nToday, I implemented my laravel 8 result. I started learning laravel 8 on 12/20/2022. This repository was created on 24/12/2022. I created a simple database using laravel framework with its implementation using rest-API\n\n## Code Explanation\n\nI used the help of \n```\nphp artisan make:model Transaction -m\n``` \nto create the model\nthen the file ```2022_12_24_075759_create_transactions_table``` will be automatically created\n\nthen I modified the file so that a new table would be created\n\n```php\npublic function up()\n{\n    Schema::create('transactions', function (Blueprint $table) {\n        $table-\u003eid();\n        $table-\u003estring('title');\n        $table-\u003edouble('amount');\n        $table-\u003etimestamp('time')-\u003edefault(now());\n        $table-\u003eenum('type', ['expense', 'revenue']); // Hanya bisa diisi sesuai parameter ke 2\n        $table-\u003etimestamps();\n    });\n}\n```\n\ninside the ```Transaction.php``` file I added the following code\n```php\nclass Transaction extends Model\n{\n    use HasFactory;\n\n    protected $fillable = ['title', 'amount', 'time', 'type'];\n}\n```\n\nto make the table I use the help of ```php artisan``` \n```\nphp artisan migrate\n```\n\nthen the table will be automatically created in our database\n\nafter that, I created a controller class with the following keywords\n```\nphp artisan make:controller TransactionController --resource\n```\nthen in the TransactionController file there are several methods that aim for CRUD\n\n**GET**\n```php\npublic function index()\n{\n    $transaction = Transaction::orderBy('time', 'DESC')-\u003eget();\n    $response = [\n        'message' =\u003e 'List Transaction order by time',\n        'data' =\u003e $transaction\n    ];\n\n    return response()-\u003ejson($response, Response::HTTP_OK);\n}\n```\n\n**CREATE**\n```php\npublic function store(Request $request)\n{\n    $validator = Validator::make($request-\u003eall(), [\n        'title' =\u003e ['required'],\n        'amount' =\u003e ['required', 'numeric'],\n        'type' =\u003e ['required', 'in:expense,revenue']\n    ]);\n\n    // Jika gagal, maka keluarkan error unproccess\n    if($validator-\u003efails()){\n        return response()-\u003ejson($validator-\u003eerror(), \n        Response::HTTP_UNPROCESSABLE_ENTITY);\n    }\n\n    // Jika berhasil, maka lakukanlah hal berikut, menggunakan try catch dengan tujuan untuk menghindari kesalahan yang tidak terduga\n    try {\n        $transaction = Transaction::create($request-\u003eall());\n        $response = [\n            'message' =\u003e 'Transaction created',\n            'data' =\u003e $transaction\n        ];\n\n        return response()-\u003ejson($response, Response::HTTP_CREATED);\n    } catch (QueryException $e) {\n        return response()-\u003ejson([\n            'message' =\u003e 'Failed' . $e-\u003eerrorInfo\n        ]);\n    }\n}\n```\n\n**READ**\n```php\npublic function show($id)\n{\n    $transaction = Transaction::findOrFail($id);\n    $response = [\n        'message' =\u003e 'Detail of Transaction Resource',\n        'data' =\u003e $transaction\n    ];\n\n    return response()-\u003ejson($response, Response::HTTP_OK);\n}\n```\n\n**UPDATE**\n```php\npublic function update(Request $request, $id)\n{\n    $transaction = Transaction::findOrFail($id);\n\n    $validator = Validator::make($request-\u003eall(), [\n        'title' =\u003e ['required'],\n        'amount' =\u003e ['required', 'numeric'],\n        'type' =\u003e ['required', 'in:expense,revenue']\n    ]);\n\n    // Jika gagal, maka keluarkan error unproccess\n    if($validator-\u003efails()){\n        return response()-\u003ejson($validator-\u003eerror(), \n        Response::HTTP_UNPROCESSABLE_ENTITY);\n    }\n\n    // Jika berhasil, maka lakukanlah hal berikut, menggunakan try catch dengan tujuan untuk menghindari kesalahan yang tidak terduga\n    try {\n        $transaction-\u003eupdate($request-\u003eall());\n        $response = [\n            'message' =\u003e 'Transaction Updated',\n            'data' =\u003e $transaction\n        ];\n\n        return response()-\u003ejson($response, Response::HTTP_OK);\n    } catch (QueryException $e) {\n        return response()-\u003ejson([\n            'message' =\u003e 'Failed' . $e-\u003eerrorInfo\n        ]);\n    }\n}\n```\n\n**DELETE**\n```php\npublic function destroy($id)\n{\n    $transaction = Transaction::findOrFail($id);\n\n    try {\n        $transaction-\u003edelete();\n        $response = [\n            'message' =\u003e 'Transaction Deleted',\n        ];\n\n        return response()-\u003ejson($response, Response::HTTP_OK);\n    } catch (QueryException $e) {\n        return response()-\u003ejson([\n            'message' =\u003e 'Failed' . $e-\u003eerrorInfo\n        ]);\n    }\n}\n```\n\nAfter all the CRUD is done, then I create the route in file ```api.php```\n```php\nRoute::get('/transaction', [TransactionController::class, 'index']);\nRoute::get('/transaction/{id}', [TransactionController::class, 'show']);\nRoute::post('/transaction', [TransactionController::class, 'store']); \nRoute::put('/transaction/{id}', [TransactionController::class, 'update']);\nRoute::delete('/transaction/{id}', [TransactionController::class, 'destroy']);\n```\n\nActually, the code route is still inefficient, here is one of Laravel's defaults\n```php\nRoute::resource('/transaction', Transaction::class)-\u003eexcept(['create', 'edit']);\n```\n\nBut the code has a weakness. If we change the default method that was created the first time the TransactionController is changed, then the resource function will not work\n\n## Output \nHere I use the help of the Postman application to make the rest-API\n\n**GET**\n\n![GET](https://user-images.githubusercontent.com/92671053/209437871-c82435f5-b7d1-47e2-8666-bf26a9556677.PNG)\n\n**CREATE**\n\n![CREATED](https://user-images.githubusercontent.com/92671053/209437877-611d109c-8f79-4e60-a898-937abf75dfca.PNG)\n\n**READ**\n\n![READ](https://user-images.githubusercontent.com/92671053/209437873-1cf717a3-00e1-428d-9a10-207e5ef50aeb.PNG)\n\n**UPDATE**\n\n![UPDATE](https://user-images.githubusercontent.com/92671053/209437875-02ec0844-ab29-4453-93e5-a3b09414c799.PNG)\n\n**DELETE**\n\n![DELETED](https://user-images.githubusercontent.com/92671053/209437870-b8f773e4-fd2c-4d88-90cd-d59f7ccd8fd7.PNG)\n\nAfter all is done, the final result is as follows\n\n## Result\n\n![AFTER_DELETE](https://user-images.githubusercontent.com/92671053/209437876-55571c93-91c3-4f58-93b5-1bba90f90589.PNG)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaknoooo%2Fsimple_accountancy_restapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaknoooo%2Fsimple_accountancy_restapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaknoooo%2Fsimple_accountancy_restapi/lists"}