承接 navjot/laravel-api-responder 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

navjot/laravel-api-responder

Composer 安装命令:

composer require navjot/laravel-api-responder

包简介

A Reusable Laravel consistent API response package for web and mobile apps

README 文档

README

License Packagist Version Laravel Version

A Reusable Laravel consistent API response package for web and mobile apps

📘 Introduction

Laravel API Responder is a lightweight Laravel package for generating clean, standardized API responses with minimal code.
It includes pre-configured methods to handle HTTP status codes, success, error, validation failures, and more.

✨ Features

  • ✅ Consistent and clean JSON API response format
  • ✅ Predefined HTTP status codes
  • ✅ Reusable trait for any controller
  • ✅ Works out of the box — no configuration needed
  • ✅ PSR-4 & Laravel auto-discovery support
  • ✅ Compatible with Laravel 10, 11, and 12+

📦 Installation

composer require navjot/laravel-api-responder

📥 Importing ApiResponder

use Navjot\Laravel\ApiResponder;

✅ Option 1: Use in a Single Controller

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Navjot\Laravel\ApiResponder;

class TestController extends Controller
{
    use ApiResponder;

    public function index(Request $request)
    {
        return $this->sendSuccess("Response message", ['foo' => 'bar']);
    }
}

🌐 Option 2: Global Import for All Controllers

To enable ApiResponder globally in every controller, add it to Laravel’s default base controller: app/Http/Controllers/Controller.php file.

<?php

namespace App\Http\Controllers;

use Navjot\Laravel\ApiResponder;

abstract class Controller
{
    use ApiResponder;
}

🧠 Usage Examples

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Navjot\Laravel\ApiResponder;
use Illuminate\Support\Facades\Validator;

//Feel Free To Visit https://github.com/navjotsinghprince
class TestController extends Controller {
    
   use ApiResponder;

    /**
     * Example 1...
     */
    public function example1(Request $request)
    {
        $collection = collect([1, 2, 3]);

        $class_obj = new \stdClass();
        $class_obj->name="Navjot Singh";

        $response = [
            "string" => "Navjot Singh",
            "int" => 1,
            "float" => 3.14,
            "boolean" => true,
            "array" => ["prince", "ferozepuria"],
            "collection" => $collection,
            "class_object" => $class_obj,
            "null_value" => null,
            "empty_string" => "",
            "empty_array" => [],
        ];

        return $this->sendSuccess(self::SUCCESS,$response);

      }


    /**
     * Example 2...
     */
    public function example2(Request $request)
    { 
        $validator = Validator::make($request->all(), [
            'name' => 'required',
            'email'=>'required|email'
        ]);

        if ($validator->fails()) {
            return $this->validationFailed(self::ALL_FIELDS_REQUIRED, $validator->errors());
        }

      }


    /**
     * Example 3...
     * Usage With Custom Message
     */
    public function example3(Request $request)
    { 
        $data = ["name" => "Navjot Singh"];
        return $response->sendSuccess("Your custom success message here...",  $data);
    }

    
    }

⚙️ Available Methods

<?php

   $response = [
      "name" => "Navjot Singh",
      "email" => "navjotsinghprince@icloud.com",
      "website" => "https://github.com/navjotsinghprince"
    ];

    return $this->sendSuccess("eg. Request completed successfully", $response);

    return $this->sendSuccessWith("eg. Request processed successfully","total",$response);

    return $this->sendFailure("eg. Unable to process your request at this time",$response);

    return $this->validationFailed("eg. Validation failed. Please check your input",$response);

    return $this->notFound("eg. The requested resource was not found",$response);

    return $this->unauthorized("eg. Authentication required. Please log in");

    return $this->forbidden("eg. You do not have permission to access this resource");

    return $this->badRequest("eg. An error occurred while processing your request");

💡 Tips

💡 Tip: Use Available Messages: SUCCESS , FAILED , ALL_FIELDS_REQUIRED , SOMETHING_WRONG , SOMETHING_WRONG_LATER.

💡 Tip: Best practice: Add the ApiResponder to app/Http/Controllers/Controller.php to avoid importing in every controller manually.

<?php
    return $this->sendSuccess(self::SUCCESS, [...]);
    return $this->sendFailure(self::FAILED, [...]);
    return $this->validationFailed(self::ALL_FIELDS_REQUIRED, [...]);
    return $this->sendFailure($this::SOMETHING_WRONG, ['same work as self keyword']);
    return $this->sendFailure($this::SOMETHING_WRONG_LATER, [...]);

👨‍💻 Author & Lead Developer of Laravel API Responder

Navjot Singh

See also the site of contributor who participated in this package.

📬 Contact

If you discover any question within package, please send an e-mail to Navjot Singh via navjotsinghprince@icloud.com. Your all questions will be answered.

📓 Changelog

Please see changelog.md for what has changed recently.

☕ Buy Me A Coffee! ☕

Feel free to buy me a coffee at Buy me a coffee! ☕, I would be really grateful for anything, be it coffee or just a kind comment towards my work, that helps me a lot.

💰 Donation

The package is completely free to use, however, it has taken a lot of time to build. If you would like to show your appreciation by leaving a small donation, you can do so by clicking here here. Thanks!

📄 License

This project is licensed under the MIT License - see the LICENSE.md file for details.

navjot/laravel-api-responder 适用场景与选型建议

navjot/laravel-api-responder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 07 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「json」 「api」 「response」 「backend」 「https」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 navjot/laravel-api-responder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 navjot/laravel-api-responder 我们能提供哪些服务?
定制开发 / 二次开发

基于 navjot/laravel-api-responder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 28
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-12