{"id":21240791,"url":"https://github.com/mrtimofey/laravel-admin-api","last_synced_at":"2026-03-06T07:03:06.356Z","repository":{"id":57020673,"uuid":"112459901","full_name":"mrTimofey/laravel-admin-api","owner":"mrTimofey","description":"API backend for administration panels","archived":false,"fork":false,"pushed_at":"2020-05-10T11:25:36.000Z","size":85,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-03T21:45:37.701Z","etag":null,"topics":["admin","administration-panel","api","api-backend","laravel","laravel-package"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrTimofey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-29T10:15:53.000Z","updated_at":"2021-04-27T09:18:12.000Z","dependencies_parsed_at":"2022-08-23T12:20:35.034Z","dependency_job_id":null,"html_url":"https://github.com/mrTimofey/laravel-admin-api","commit_stats":null,"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"purl":"pkg:github/mrTimofey/laravel-admin-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrTimofey%2Flaravel-admin-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrTimofey%2Flaravel-admin-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrTimofey%2Flaravel-admin-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrTimofey%2Flaravel-admin-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrTimofey","download_url":"https://codeload.github.com/mrTimofey/laravel-admin-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrTimofey%2Flaravel-admin-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264652620,"owners_count":23644289,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["admin","administration-panel","api","api-backend","laravel","laravel-package"],"created_at":"2024-11-21T00:53:26.638Z","updated_at":"2025-10-05T05:46:15.716Z","avatar_url":"https://github.com/mrTimofey.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"API backend for administration panels based on [vue-admin-front](https://github.com/mrTimofey/vue-admin) package.\n\n[Demo](http://admin.shit-free.space).\n\n## Requirements\n\n* PHP 7.1\n* Laravel 5\n\n## Install\n\n```bash\nnpm i -D vue-admin-front\ncomposer require mr-timofey/laravel-admin-api\n```\n\nFollow installation instructions from dependent packages:\n[mr-timofey/laravel-aio-images](https://github.com/mrTimofey/laravel-aio-images) for images processing,\n[mr-timofey/laravel-simple-tokens](https://github.com/mrTimofey/laravel-simple-tokens) for authorization.\n\n**For Laravel \u003c= 5.4** add `MrTimofey\\LaravelAdminApi\\ServiceProvider` to your `app.providers` config.\n\n```bash\nphp artisan vendor:publish --provider=\"MrTimofey\\LaravelAdminApi\\ServiceProvider\"\n```\n\nLook to `config/admin_api.php` for further package configuration instructions.\n\nFollow [vue-admin-front quick start guide](https://mr-timofey.gitbooks.io/vue-admin/content/quick-start.html).\n\nFor development purpose you may also want to execute `npm i -D concurrently` and add this script to your npm scripts:\n\n```json\n{\n\t\"scripts\": {\n\t\t\"dev\": \"concurrently --kill-others -n \\\" api ,admin\\\" -c \\\"blue,white\\\" \\\"php artisan serve\\\" \\\"npm run admin:dev\\\"\"\n\t}\n}\n```\n\nIt will run a development PHP server on port 8000 and vue-admin-front dev server on port 8080.\n\n## Authentication and authorization\n\nThis package uses [mr-timofey/laravel-simple-tokens](https://github.com/mrTimofey/laravel-simple-tokens)\nto maintain authentication and authorization logic.\n\nYou can change a guard which is used for API by setting a proper `auth:{guard name}` middleware and guard name\nin `admin_api.api_middleware` and `admin_api.api_guard` config respectively.\n\nRemove `auth` middleware if you want to disable authorization.\n\nAlso you can completely replace authentication and authorization logic by rebinding auth controller class:\n`app()-\u003ebind(\\MrTimofey\\LaravelAdminApi\\Http\\Controllers\\Auth::class, YourController::class)`\n\n## Models configuration\n\nAdmin API will try to guess attribute types and generate field names by capitalizing attribute names using model's:\n* `$visible` to get a list of fields to display on entity index page (if not set explicitly)\n* `$fillable` to get a list of fields for editing (if not set explicitly)\n* `$hidden` fields will receive a `password` field type\n* `$dates` fields will receive a `datetime` field type\n* `$casts` will just set field types as-is (don't worry, `vue-admin-front` supports any Eloquent compatible types by aliasing them)\n* belongsTo, hasMany and belongsToMany relations will just work\n\nYou can also implement a `MrTimofey\\LaravelAdminApi\\Contracts\\ConfiguresAdminHandler` interface and define a\n`configureAdminHandler($handler)` method to make things more controllable.\n\nAvailable field types and their options are described in\n[vue-admin-front field types docs](https://mr-timofey.gitbooks.io/vue-admin/content/fields.html#available-field-types).\nSame for fields formatting for model index page\n[vue-admin-front display types docs](https://mr-timofey.gitbooks.io/vue-admin/content/displays.html#available-display-types).\n\nUsage example:\n\n```php\n\u003c?php\n\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Illuminate\\Database\\Eloquent\\Relations\\BelongsTo;\nuse Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany;\nuse Illuminate\\Http\\Request;\nuse MrTimofey\\LaravelAdminApi\\Contracts\\ConfiguresAdminHandler;\nuse MrTimofey\\LaravelAdminApi\\ModelHandler;\n\nclass Post extends Model implements ConfiguresAdminHandler\n{\n    protected $casts = [\n        'published' =\u003e 'bool'\n    ];\n\n    public function category(): BelongsTo\n    {\n        return $this-\u003ebelongsTo(Category::class);\n    }\n\n    public function tags(): BelongsToMany\n    {\n        return $this-\u003ebelongsToMany(Tag::class);\n    }\n\n    public function scopeOnlyDrafts(Builder $q): Builder\n    {\n        return $q-\u003ewhereRaw('draft IS TRUE');\n    }\n\n    public function configureAdminHandler(ModelHandler $handler): void\n    {\n        $handler-\u003esetTitle('Posts')\n            -\u003esetCreateTitle('Creating new post')\n            // placeholders can be used, see more: https://mr-timofey.gitbooks.io/vue-admin/placeholders.html\n            -\u003esetItemTitle('Editing post #{{ id }}')\n\n            // allow only these methods (everything is allowed by default)\n            -\u003eallowActions(['index', 'item', 'create', 'update', 'destroy'])\n            // ...or use policies instead\n            -\u003eusePolicies(true,\n                // optional policy method prefix (Policy::adminActionIndex, Policy::adminActionCreate, etc.)\n                'adminAction')\n\n            -\u003eaddPreQueryModifier(function(Builder $q, Request $req): void {\n                // modify index query just after Model::newQuery() is called\n                $user = $req-\u003euser();\n                if ($user-\u003erole !== 'god') {\n                    $q-\u003ewhere('author_user_id', $user-\u003egetKey());\n                }\n            })\n            -\u003eaddPostQueryModifier(function(Builder $q,Request $req): void {\n                // modify index query just before execution\n                // useful if you want to set default sort order\n                $q-\u003eorderByDesc('created_at');\n            })\n            // automatically search with LIKE\n            -\u003esetSearchableFields(['title', 'summary'])\n            // ...or/and set custom search callback\n            -\u003esetSearchCallback(function(\n                Builder $q,\n                Request $req,\n                array $searchableFields): void {\n                    $q-\u003esearchLikeAGod($req-\u003eget('search'));\n                })\n\n            // index page filters\n            -\u003esetFilterFields([\n                // auto relation filter\n                'category',\n                // see more about available prefix modifiers in ModelHandler::applyFilters phpdoc\n                '\u003e~created_at' =\u003e [\n                    'title' =\u003e 'Created after',\n                    'type' =\u003e 'datetime'\n                ],\n                // checkbox, applies scopeOnlyDrafts when checked\n                'drafts' =\u003e [\n                    'scope' =\u003e 'onlyDrafts',\n                    'type' =\u003e 'switcher'\n                ]\n            ])\n\n\t\t\t// index page table columns\n            -\u003esetIndexFields([\n                'id',\n                'title',\n                // will be automatically formatted as datetime if $this-\u003etimestamps === true\n                // or if $this-\u003edates includes 'created_at' field\n                'created_at',\n                // you can provide only title this way\n                'updated_at' =\u003e 'Last update date and time'\n            ])\n\n\t\t\t// item creating/editing form fields\n            -\u003esetItemFields([\n                'title',\n                // this just works\n                'category', // categories should be added to api_admin.models config\n                // this should just work as well but we want some customizations\n                'tags' =\u003e [\n                    'title' =\u003e 'Attach tags',\n                    // 'type' =\u003e 'relation', // not necessary if field name is same as a relation method\n                    // 'entity' =\u003e 'tags', // tags should be added to api_admin.models config\n                    // placeholders can be used, see more: https://mr-timofey.gitbooks.io/vue-admin/placeholders.html\n                    'display' =\u003e '{{ name }}',\n                    // relation widget will allow user to create new tags in-place\n                    'allowCreate' =\u003e true,\n                    // this field will be filled with the widget's search box input text\n                    'createField' =\u003e 'name',\n                    // fill some other fields with fixed values while creating new tag\n                    'createDefaults' =\u003e ['description' =\u003e 'New tag'],\n                    // customize suggestions query\n                    'queryParams' =\u003e [\n                        'sort' =\u003e ['sort' =\u003e 'asc']\n                    ]\n                ],\n                'content' =\u003e ['type' =\u003e 'wysiwyg'],\n                // $casts =\u003e ['published' =\u003e 'bool'] will automatically set the right field type for you (checkbox)\n                'published'\n            ])\n\n            // creating/editing validation rules (use $this to refer to the currently editing model instance)\n            -\u003esetValidationRules([\n                'tags' =\u003e ['array', 'between:3,8'],\n                'category' =\u003e ['required'],\n                'some_unique_field' =\u003e [\n                    'required',\n                    'unique,' . $this-\u003egetTable() . ',some_unique_field' .\n                    \t($this-\u003eexists ? (',' . $this-\u003egetKey() . ',' . $this-\u003egetKeyName()) : '')\n\t\t\t\t]\n            ])\n            // ...or/and defined custom validation callback\n            -\u003esetValidationCallback(\n                /**\n                 * @throws \\Illuminate\\Validation\\ValidationException\n                 */\n                function(\n                    \\Illuminate\\Http\\Request $req,\n                    array $rules,\n                    array $messages,\n                    // gathered from item fields configuration\n                    array $titles\n                ) {\n                    $req-\u003evalidate([ /* whatever */ ]);\n                })\n\t\t\t// override default error messages\n            -\u003esetValidationMessages([\n                'category.required' =\u003e 'No category - no post'\n            ]);\n    }\n}\n```\n## Events\n\nEvery action within an administrative panel can be tracked and processed with the Laravel's event system.\nAvailable events:\n\n```php\n\u003c?php\n\nnamespace MrTimofey\\LaravelAdminApi\\Events;\n\n// abstract base class for all events (holds user identifier)\nModelEvent::class;\n\n// single model instance action events\nSingleModelEvent::class; // abstract base class for single model instance action events (holds item identifier)\nModelCreated::class;\nModelUpdated::class; // holds attributes changes, more info in phpdoc of this class\nModelDestroyed::class;\n\n// bulk destroy (holds destroyed instances' identifiers)\nBulkDestroyed::class;\n```\n\n### Tracking changes for ModelUpdated event\n\nBy default `ModelUpdated` will track only instance attributes (using Eloquent's `Model::getDirty()`)\nmethod and relation changes.\n\nYou can implement `MrTimofey\\LaravelAdminApi\\Contracts\\HasCustomChanges` interface and define `getCustomChanges()`\nmethod to enrich `ModelUpdated::$changes` field with any additional information you want to track. Default format\nis to return array `['field_name' =\u003e [$oldValue, $newValue], ...]`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrtimofey%2Flaravel-admin-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrtimofey%2Flaravel-admin-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrtimofey%2Flaravel-admin-api/lists"}