nevestul4o/network-controller

A basic API controller set for laravel, designed to work with dingo/api

Downloads

71

Stars

0

Version

v1.5.4

NetworkController

  • All controllers should extend it.
  • For example, if we need ot add the EmployeeController, to the employee endpoint, add the following entry in the api.php in the routes folder:
    $api->resource('employee', 'EmployeeController');

BaseModel

  • Abstract class, cannot be used standalone
  • All models should extend it
  • All models need to be placed in the \App\Http\Models\ folder
  • Ideally, one model should have one controller, which extends NetworkController

BaseUser

  • Abstract class, cannot be used standalone
  • Provides basic user account functionality
  • It MUST be extended by a model called User, placed in the \App\Http\Models\ folder

FileUploadController and ImageUploadController

Add the following code in the api.php in the routes folder:

    $api->group(
        ['namespace' => 'Nevestul4o\NetworkController\Controllers'],
        static function ($api) {
            $api->get('images/{width}/{name}', '[email protected]')->name('getImage');
            $api->post('upload', '[email protected]');
        }
    );

LoginController and ChangePasswordController

  • Pre-made controller classes, providing basic functionality for login/logout and password changes
  • They require a Model, called User, placed in the \App\Http\Models\ folder, extending BaseUser
  • Change the namespace of the user provider in auth.php to \App\Http\Models\User
  • They require a Transformer, called UserTransformer, placed in the App\Http\Models\Transformers\ folder
  • Functions can be freely overridden
  • Can be used by defining these routes in the api.php:
    $api->post('login', 'Auth\[email protected]')->name('login');
    $api->get('login', 'Auth\[email protected]')->name('getCurrentUser');
    $api->get('logout', 'Auth\[email protected]')->name('logout');
    
    $api->post('change-password', 'Auth\[email protected]')->name('changePassword');
    $api->post('change-password-forced', 'Auth\[email protected]')->name('changePasswordForced');
  • WARNING - the function changePasswordForced in ChangePasswordController is NOT secured! Take care te secure it manually, when defining the API route, or override it!
NKozhuharov

Author

NKozhuharov