Selamat Pagi
Solution:
To add a status column and amend existing APIs in the Laravel project, we will need to follow these steps:
1. Add Status Column:
a) Create a new migration file using the command `php artisan make:migration add_status_to_table_name_table` where `table_name` is the name of the table where we want to add the status column.
b) In the newly created migration file, add the following code to add the status column:
```
Schema::table('table_name', function (Blueprint $table) {
$table->tinyInteger('status')->default(1);
});
```
c) Run the migration using the command `php artisan migrate` to add the status column to the table.
2. Amend Existing APIs:
a) Open the controller file for the API where we want to add the status parameter.
b) Add a new parameter for the status in the function's parameter list, for example:
```
public function getProducts(Request $request, $status) {
// code goes here
}
```
c) In the function body, use the `$status` variable to filter the data based on the status.
3. Adding 2 Columns:
a) Create a new migration file using the command `php artisan make:migration add_new_columns_to_table_name_table`.
b) In the newly created migration file, add the following code to add the 2 new columns:
```
Schema::table('table_name', function (Blueprint $table) {
$table->string('column_name_1');
$table->string('column_name_2');
});
```
c) Run the migration using the command `php artisan migrate` to add the 2 new columns to the table.
Note: Make sure to replace `table_name` with the actual name of the table and `column_name_1` and `column_name_2` with the names of the new columns.
4. Additional Considerations:
a) In the case of APIs, make sure to update the API documentation to include the new parameters.
b) If the new columns are required fields, add the validation rules in the controller and make the necessary changes in the front-end to pass the values for those fields.
c) If any data is already present in the table, make sure to handle it properly while adding the new columns to avoid any data loss.
Conclusion:
Following these steps will allow us to add a status column and amend existing APIs, and add 2 new columns to the Laravel project efficiently. It is essential to make sure that all the changes are thoroughly tested before deploying them to the live environment.
Best regards,
Giáp Văn Hưng