1. Go to this page and download the library: Download fenox/laravel-api-json 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/ */
fenox / laravel-api-json example snippets
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->text('description')->nullable();
$table->timestamps();
});
}
protected $fillable = ['name', 'description']; // Example fields
public function rules(): array
{
return [
'name' => '
use Fenox\ApiBase\Helpers\ResponseHelper; // Ensure you import the ResponseHelper from the package
public function index(): JsonResponse
{
$query = $this->model::query();
if (request()->has('filter')) {
$query->where('name', 'like', '%' . request('filter') . '%');
}
$results = $query->orderBy($this->sortBy)
->paginate($this->paginate);
return ResponseHelper::success($results, 'Filtered list retrieved successfully', 200);
}
namespace App\Http\Controllers;
use Fenox\ApiBase\Controllers\BaseApiController;
class CustomApiController extends BaseApiController
{
public function customMethod()
{
// Custom logic that applies to all your API controllers
}
}