PHP code example of webmonks / laravel-api-modules
1. Go to this page and download the library: Download webmonks/laravel-api-modules library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webmonks / laravel-api-modules example snippets
// This happens automatically - no manual binding needed!
$this->app->bind(
BlogRepositoryInterface::class,
BlogRepository::class
);
// app/Helpers/AutoloadFiles/api_helpers.php
function transform_response($data, $message = 'Success') {
return ['data' => $data, 'message' => $message];
}
// Available everywhere in your app automatically!
return transform_response($users, 'Users retrieved successfully');
// Use anywhere in your application
$discounted_price = calculate_discount($product->price, 15);
$formatted_price = format_currency($discounted_price);
// stubs/laravel-api-modules/controller.stub
class {{model}}Controller extends Controller
{
// Your custom controller template
// Add your standard methods, middleware, etc.
}
// app/Models/BaseModel.php - Auto-generated, customize as needed
abstract class BaseModel extends Model
{
use ApiResponser, ActivityLogHelper, UserUpdater;
// Add your common model methods here
public function scopeActive($query) {
return $query->where('is_active', true);
}
}
// tests/Feature/Modules/Blog/BlogFeatureTest.php
class BlogFeatureTest extends TestCase
{
public function test_can_list_blogs()
{
$response = $this->getJson('/api/blogs');
$response->assertStatus(200)
->assertJsonStructure(['data', 'message']);
}
}