{"id":21542572,"url":"https://github.com/bastinald/laravel-livewire-model","last_synced_at":"2025-03-17T23:52:34.224Z","repository":{"id":62492196,"uuid":"401556523","full_name":"bastinald/laravel-livewire-model","owner":"bastinald","description":"Laravel Livewire form data modelling trait.","archived":false,"fork":false,"pushed_at":"2021-09-11T03:09:09.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-24T08:43:37.785Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bastinald.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}},"created_at":"2021-08-31T03:08:05.000Z","updated_at":"2021-09-11T03:09:12.000Z","dependencies_parsed_at":"2022-11-02T11:30:55.956Z","dependency_job_id":null,"html_url":"https://github.com/bastinald/laravel-livewire-model","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bastinald%2Flaravel-livewire-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bastinald%2Flaravel-livewire-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bastinald%2Flaravel-livewire-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bastinald%2Flaravel-livewire-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bastinald","download_url":"https://codeload.github.com/bastinald/laravel-livewire-model/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244130283,"owners_count":20402753,"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-24T05:10:00.332Z","updated_at":"2025-03-17T23:52:34.201Z","avatar_url":"https://github.com/bastinald.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Livewire Model\n\nThis package contains a trait which makes Laravel Livewire form data model manipulation a breeze. No more having to create a Livewire component property for every single form input. All form data will be placed inside the `$model` property array.\n\n## Documentation\n\n- [Installation](#installation)\n- [Usage](#usage)\n    - [The WithModel Trait](#the-withmodel-trait)\n    - [Getting Model Data](#getting-model-data)\n    - [Setting Model Data](#setting-model-data)\n    - [Binding Model Data](#binding-model-data)\n    - [Validating Model Data](#validating-model-data)\n\n## Installation\n\nRequire the package via composer:\n\n```console\ncomposer require bastinald/laravel-livewire-model\n```\n\n## Usage\n\n### The WithModel Trait\n\nAdd the `WithModel` trait to your Livewire components:\n\n```php\nclass Login extends Component\n{\n    use WithModel;\n    \n    //\n}\n```\n\n### Getting Model Data\n\nGet all model data as an array:\n\n```php\n$array = $this-\u003egetModel();\n```\n\nGet a single value:\n\n```php\n$email = $this-\u003egetModel('email');\n```\n\nGet an array of specific values:\n\n```php\n$credentials = $this-\u003egetModel(['email', 'password']);\n```\n\n### Setting Model Data\n\nSet a single value:\n\n```php\n$this-\u003esetModel('name', 'Kevin');\n```\n\nSet values using an array:\n\n```php\n$this-\u003esetModel([\n    'name' =\u003e 'Kevin',\n    'email' =\u003e 'kevin@example.com',\n]);\n```\n\nSet values using Eloquent model data:\n\n```php\n$this-\u003esetModel(User::first());\n```\n\n### Binding Model Data\n\nJust prepend your `wire:model` attribute with `model.`:\n\n```html\n\u003cinput \n    type=\"email\" \n    placeholder=\"{{ __('Email') }}\"\n    class=\"form-control\" \n    wire:model.defer=\"model.email\"\n\u003e\n```\n\n### Validating Model Data\n\nUse the `validateModel` method to validate model data:\n\n```php\n$this-\u003evalidateModel([\n    'name' =\u003e ['required'],\n    'email' =\u003e ['required', 'email'],\n]);\n```\n\nThis method works just like the Livewire `validate` method, so you can specify your rules in a separate `rules` method if you prefer.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbastinald%2Flaravel-livewire-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbastinald%2Flaravel-livewire-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbastinald%2Flaravel-livewire-model/lists"}