{"id":20012307,"url":"https://github.com/archtechx/livewire-access","last_synced_at":"2025-07-01T12:36:54.247Z","repository":{"id":39715374,"uuid":"348770137","full_name":"archtechx/livewire-access","owner":"archtechx","description":"Control frontend access to properties/methods in Livewire using PHP 8 attributes.","archived":false,"fork":false,"pushed_at":"2023-02-16T16:05:46.000Z","size":38,"stargazers_count":95,"open_issues_count":1,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-20T09:01:49.542Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/archtechx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"stancl"}},"created_at":"2021-03-17T16:02:26.000Z","updated_at":"2024-07-30T05:12:16.000Z","dependencies_parsed_at":"2024-11-13T07:30:23.085Z","dependency_job_id":"0c2424fa-ad95-4cbd-bb66-434f51a37d9e","html_url":"https://github.com/archtechx/livewire-access","commit_stats":{"total_commits":23,"total_committers":3,"mean_commits":7.666666666666667,"dds":"0.26086956521739135","last_synced_commit":"9aae65bd8014f0afd41681e2863ab471ccadde9b"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":"stancl/package-template","purl":"pkg:github/archtechx/livewire-access","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archtechx%2Flivewire-access","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archtechx%2Flivewire-access/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archtechx%2Flivewire-access/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archtechx%2Flivewire-access/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/archtechx","download_url":"https://codeload.github.com/archtechx/livewire-access/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archtechx%2Flivewire-access/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262701745,"owners_count":23350612,"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-13T07:29:41.839Z","updated_at":"2025-07-01T12:36:54.163Z","avatar_url":"https://github.com/archtechx.png","language":"PHP","funding_links":["https://github.com/sponsors/stancl"],"categories":[],"sub_categories":[],"readme":"# Livewire Access\n\nThis package adds PHP 8.0 attribute support to Livewire. In specific, the attributes are used for flagging component properties and methods as *frontend-accessible*.\n\nThe package ships with two pairs of traits and attributes. One for *explicit* access, and one for *implicit* access.\n\n## How it works\n\n- Components which implement the trait for **explicit** access will *deny* access to all properties and methods if they don't have the `#[FrontendAccess]` attribute.\n- Components which implement the trait for **implicit** access will *allow* access to all properties and methods unless they have the `#[BlockFrontendAccess]` attribute.\n\nThis acts as a layer on top of Livewire's `public`-check logic, but gives you much more fine grained control.\n\n## Why use this?\n\nSometimes, you may want allow access to a component's property in PHP — outside the component — while not allowing access from the frontend. For that, you can use the `WithImplicitAccess` trait. Frontend access will be enabled for all properties by default, but you can disable it for a specific property (or method).\n\nOther times, you may simply want more assurance than Livewire provides out of the box. The `WithExplicitAccess` trait is made for that. It disables all frontend access, and requires you to manually enable it on specific properties/methods.\n\nThe second option is recommended, because it provides the most security benefits. Accidentally making methods `public` is common, and it can cause security issues. Disabling implicit access can be especially useful on teams with junior engineers who don't yet have a full understanding of Livewire's internals, but can be very productive with it.\n\n## Practical use case\n\nSay you have a component with the following method:\n\n```php\npublic function getItemsProperty()\n{\n    return [\n      ['secret' =\u003e false, 'name' =\u003e 'Item 1'],\n      ['secret' =\u003e true, 'name' =\u003e 'Item 2'],\n      ['secret' =\u003e true, 'name' =\u003e 'Item 3'],\n      ['secret' =\u003e false, 'name' =\u003e 'Item 4'],\n    ];\n}\n```\n\nIn the Blade template, you want to loop through the items and only display the non-secret ones.\n\n```html\n@foreach($this-\u003eitems-\u003efilter(...) as $item)\n```\n\nHowever, the entire dataset will be accessible from the frontend, even if you're not rendering any of the secret items.\n\nThe user can easily fetch the Livewire component in Developer Tools and make a call like this:\n\n```js\ncomponent.call('getItemsProperty');\n```\n\nIt will return all of the data returned by the `getItemsProperty()` method in PHP.\n\n\u003cimg width=\"348\" alt=\"Screen Shot 2021-03-17 at 21 53 00\" src=\"https://user-images.githubusercontent.com/33033094/111536933-26f87680-876b-11eb-98c5-8b7f40f1a5de.png\"\u003e\n\nYou may think that in this case, you should just make the method `protected`/`private`. However, that would make it inaccessible from the Blade template. Even though Livewire uses `$this` in the template, it's accessing the object from the outside.\n\nWhich means that although Blade templates are completely server-rendered, and let you access any PHP code in a secure way, you cannot access many of the properties or methods of Livewire components without making them public, which can cause unexpected data leaks.\n\nWith this package, you can keep the property public and access it anywhere in PHP, while completely blocking any attempts at accessing it from the frontend.\n\n## Installation\n\nPHP 8 is required.\n\n```sh\ncomposer require leanadmin/livewire-access\n```\n\n## Usage\n\nThis package doesn't make any changes to your existing code. Components which don't implement either one of its traits will not be affected.\n\n### Explicit access\n\nTo enable the explicit access mode, i.e. only enable access to properties/methods that explicitly allow it, use the `WithExplicitAccess` trait.\n\n```php\nuse Livewire\\Component;\nuse Lean\\LivewireAccess\\WithExplicitAccess;\nuse Lean\\LivewireAccess\\FrontendAccess;\n\nclass MyComponent extends Component\n{\n    // Use the trait on your component to enable this functionality\n    use WithExplicitAccess;\n\n    // Accessing this from the frontend will throw an exception\n    public string $inaccessible;\n\n    #[FrontendAccess]\n    public string $accessible; // This property allows frontend access\n\n    public function secretMethod()\n    {\n        // Calling this from the frontend will throw an exception\n    }\n\n    #[FrontendAccess]\n    public function publicMethod()\n    {\n        // This method allows frontend access\n    }\n}\n```\n\n### Implicit access\n\nTo enable the implicit access mode, i.e. keep using the same mode , use the `WithExplicitAccess` trait.\n\n```php\nuse Livewire\\Component;\nuse Lean\\LivewireAccess\\WithImplicitAccess;\nuse Lean\\LivewireAccess\\BlockFrontendAccess;\n\nclass MyComponent extends Component\n{\n    // Use the trait on your component to enable this functionality\n    use WithImplicitAccess;\n\n    // This property allows frontend access\n    public string $accessible;\n\n    #[BlockFrontendAccess]\n    public string $inaccessible; // This property blocks frontend access\n\n    public function publicMethod()\n    {\n        // This method allows frontend access\n    }\n\n    #[BlockFrontendAccess]\n    public function secretMethod()\n    {\n        // This method blocks frontend access\n    }\n}\n```\n\n### Details\n\n- The properties still need to be `public` to be accessible.\n- The thrown exceptions are identical to those that Livewire would throw if the properties/methods were not public.\n\n## Development\n\nRunning all checks locally:\n\n```sh\n./check\n```\n\nRunning tests:\n\n```sh\nphpunit\n```\n\nCode style will be automatically fixed by php-cs-fixer.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchtechx%2Flivewire-access","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farchtechx%2Flivewire-access","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchtechx%2Flivewire-access/lists"}