Answers for "laravel api response trait"

PHP
0

laravel api response trait

trait RespondsWithHttpStatus
{
    protected function success($message, $data = [], $status = 200)
    {
        return response([
            'success' => true,
            'data' => $data,
            'message' => $message,
        ], $status);
    }

    protected function failure($message, $status = 422)
    {
        return response([
            'success' => false,
            'message' => $message,
        ], $status);
    }
}
Posted by: Guest on September-02-2020
0

laravel apiresource

When declaring resource routes that will be consumed by APIs,
you will commonly want to exclude routes that present HTML
templates such as "create" and "edit"

//Route=>
use App\Http\Controllers\PhotoController;
Route::apiResource('photos', PhotoController::class);

//artisan command =>
php artisan make:controller PhotoController --api
Posted by: Guest on July-24-2021

Browse Popular Code Answers by Language