This is my controller api helper for laravel app
- Move file ControllerHelpers.php to App\Traits
- then add ControllerHelpers trait in \App\Http\Controllers\Controller
...
use App\Traits\ControllerHelpers;
...
...
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
use ControllerHelpers;
...
Simple use:
$users = \App\Models\User::all();
return $this->reponseJsonData($users);
some time we need to do some driven design like using service and repository. You can simpify to use the UploadFile.php
instead the entire controller helpers
use \App\Traits\UploadFile;
...
$this->uploadFile($request->file('file-name'), 'file-folder');
...
$this->deleteFile($model->file_name ?? '');
$this->uploadFile($request->file('file-name'), 'file-folder');
...