{"id":19450895,"url":"https://github.com/morning-train/laravelfields","last_synced_at":"2026-04-19T15:07:07.470Z","repository":{"id":57019846,"uuid":"177119600","full_name":"Morning-Train/LaravelFields","owner":"Morning-Train","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-08T05:05:03.000Z","size":86,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-08T23:03:53.620Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Morning-Train.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-22T10:23:23.000Z","updated_at":"2021-10-05T13:41:03.000Z","dependencies_parsed_at":"2024-11-10T16:40:49.168Z","dependency_job_id":null,"html_url":"https://github.com/Morning-Train/LaravelFields","commit_stats":{"total_commits":52,"total_committers":5,"mean_commits":10.4,"dds":0.3076923076923077,"last_synced_commit":"0eea88cb2f66c8b0a3f88a6e6b26772ba7d97b22"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2FLaravelFields","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2FLaravelFields/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2FLaravelFields/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morning-Train%2FLaravelFields/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Morning-Train","download_url":"https://codeload.github.com/Morning-Train/LaravelFields/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240637767,"owners_count":19833190,"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":[],"created_at":"2024-11-10T16:39:22.860Z","updated_at":"2025-11-18T15:03:56.521Z","avatar_url":"https://github.com/Morning-Train.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Fields\n\n## Install\n\nVia Composer\n\n``` bash\n$ composer require morningtrain/laravel-fields\n```\n\n## Features\nA field is at its core responsible for taking a request value \nand applying it to an eloquent model attribute.\n\n### Applying fields\nHaving a field and a model instance, it can be applied like this:\n\n```php\n$field-\u003eupdate($model, $request, FieldContract::BEFORE_SAVE);\n```\nand the following for post-save. \n\n```php\n$field-\u003eupdate($model, $request, FieldContract::AFTER_SAVE);\n```\nSome fields will know that it should run before saving the model (like setting a basic attribute value)\nwhile some fields should be run after (attaching related models).\n\nA more complete example would be:\n\n```php\n$request = request();\n\nif (is_array($fields) \u0026\u0026 !empty($fields)) {\n\n    foreach ($fields as $field) {\n        $field-\u003eupdate($model, $request, FieldContract::BEFORE_SAVE);\n    }\n\n    $model-\u003esave();\n\n    foreach ($fields as $field) {\n        $field-\u003eupdate($model, $request, FieldContract::AFTER_SAVE);\n    }\n\n}\n```\n\nThe example uses the following classes:\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\nuse MorningTrain\\Laravel\\Fields\\Contracts\\FieldContract;\n```\n\n\n### Fields\n\n#### Basic field\n\n```php\nField::create('name_of_attribute')\n```\n\n#### Hidden (static) field\n\n```php\nField::hidden('name_of_attribute', 'value to apply')\n```\n\n#### Belongs to many field\n\n```php\nField::belongsToMany('name_in_request')\n    -\u003erelation('name_of_relation')\n    -\u003eremoveMissing()\n```\n\n\n## Credits\nThis package is developed and actively maintained by [Morningtrain](https://morningtrain.dk).\n\n\u003c!-- language: lang-none --\u003e\n     _- _ -__ - -- _ _ - --- __ ----- _ --_  \n    (         Morningtrain, Denmark         )\n     `---__- --__ _ --- _ -- ___ - - _ --_ ´ \n         o                                   \n        .  ____                              \n      _||__|  |  ______   ______   ______ \n     (        | |      | |      | |      |\n     /-()---() ~ ()--() ~ ()--() ~ ()--() \n    --------------------------------------\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorning-train%2Flaravelfields","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorning-train%2Flaravelfields","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorning-train%2Flaravelfields/lists"}