{"id":21029415,"url":"https://github.com/devhammed/php-server-actions","last_synced_at":"2026-04-15T14:39:00.926Z","repository":{"id":204099356,"uuid":"711112127","full_name":"devhammed/php-server-actions","owner":"devhammed","description":"Next.js Server Actions but for PHP!","archived":false,"fork":false,"pushed_at":"2023-10-29T06:47:48.000Z","size":35,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-20T15:17:17.549Z","etag":null,"topics":["composer-package","laravel","laravel-package","nextjs","nextjs13","php"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/devhammed/server-actions","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/devhammed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-10-28T08:50:34.000Z","updated_at":"2024-03-12T00:30:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"3b026768-310d-4a56-8464-03e2efcaf751","html_url":"https://github.com/devhammed/php-server-actions","commit_stats":null,"previous_names":["devhammed/php-server-actions"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devhammed%2Fphp-server-actions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devhammed%2Fphp-server-actions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devhammed%2Fphp-server-actions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devhammed%2Fphp-server-actions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devhammed","download_url":"https://codeload.github.com/devhammed/php-server-actions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243466985,"owners_count":20295309,"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":["composer-package","laravel","laravel-package","nextjs","nextjs13","php"],"created_at":"2024-11-19T12:12:17.913Z","updated_at":"2025-12-29T14:06:45.096Z","avatar_url":"https://github.com/devhammed.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# devhammed/server-actions\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/devhammed/server-actions.svg?style=flat-square)](https://packagist.org/packages/devhammed/server-actions)\n\nMaking [Next.js Server Actions](https://nextjs.org/docs/app/api-reference/functions/server-actions) work in PHP!\n\nThis is a proof of concept inspired by [this tweet](https://x.com/WebReflection/status/1717853489034932631?s=20), and it's not meant to be used in production.\n\nBut it works so let's go!\n\n## Installation\n\nThe recommended way to install this package is through [Composer](https://getcomposer.org/).\n\n```bash\ncomposer require devhammed/server-actions\n```\n\nThen include the Composer autoloader in your entry file (e.g `index.php`) like:\n\n```php\n\u003c?php\n\n// File: /public/index.php\n\nrequire_once __DIR__ . '/../vendor/autoload.php';\n```\n\nBut you can also download this repository and include the provided `autoload.php` file e.g\n\n```php\nrequire_once __DIR__ . '/libs/server-actions/autoload.php';\n```\n\n## Usage\n\nYou can use this package in any PHP project, but it has first-class support for [Laravel](https://laravel.com) and all the heavy lifting is done for you.\n\nYou can skip to the [Laravel](#laravel) section if you are using Laravel.\n\nThe basic concept is that you have to initialize the Server in your entry file (e.g `index.php`) before using it by calling the `useServer()` function \nwithout any arguments which will return the instance that you can use to configure the server  endpoint and the storage for the server actions which the package currently provides\n[JsonFileServerEntry](./src/Concerns/JsonFileServerEntry.php) that stores serialized actions in a JSON file, you can implement [DevHammed\\ServerActions\\Contracts\\ServerEntry](./src/Contracts/ServerEntry.php) interface.\n\n```php\n\u003c?php\n\n// File: /public/index.php\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\nuse DevHammed\\ServerActions\\Concerns\\JsonFileServerEntry;\n\nuse function DevHammed\\ServerActions\\useServer;\n\nuseServer()\n    -\u003ewithServerActionsUrl('/server-actions.php')\n    -\u003ewithServerEntry(\n       new JsonFileServerEntry(\n           __DIR__ . '/server-actions.json',\n       ),\n    );\n\n// Other logic to include your PHP files for the request here...\n```\n\nThen you need to create the server actions handler file that was specified in the `withServerActionsUrl` method e.g `server-actions.php` that will look\nalmost the same as the entry file but with the `run()` method called at the end of the chain and nothing else, like:\n\n```php\n\u003c?php\n\n// File: /public/server-actions.php\n\nrequire __DIR__ . '/../vendor/autoload.php';\n\nuse DevHammed\\ServerActions\\Concerns\\JsonFileServerEntry;\n\nuse function DevHammed\\ServerActions\\useServer;\n\nuseServer()\n\t-\u003ewithServerActionsUrl('/server-actions.php')\n\t-\u003ewithServerEntry(\n\t\tnew JsonFileServerEntry(\n\t\t\t__DIR__ . '/server-actions.json',\n\t\t),\n\t)\n\t-\u003erun();\n```\n\nThen you can use the `useServer` helper function in the included PHP files like:\n\n```php\n\u003c?php\n    // File: /views/my-form.php\n\n    use function DevHammed\\ServerActions\\useServer;\n?\u003e\n\n\u003cform\n    method=\"post\"\n    action=\"\u003c?= useServer(function (string $name) {\n            echo 'Hello, ' . $name;\n    }) ?\u003e\"\n\u003e\n    \u003cinput type=\"hidden\" name=\"name\" value=\"Hammed\"\u003e\n    \u003cbutton type=\"submit\"\u003eGreet the creator\u003c/button\u003e\n\u003c/form\u003e\n```\n\n### Laravel\n\nThis package provides a service provider for Laravel that will automatically initialize the server and endpoint for you.\n\nYou can register the service provider in your `config/app.php` file if you are using Laravel 5.4 or below, but if you are using Laravel 5.5 or above, the package will automatically register itself using auto-discovery.\n\n```php\n\u003c?php\n\n// File: config/app.php\n\nreturn [\n    // ...\n    'providers' =\u003e [\n        // ...\n        DevHammed\\ServerActions\\ServerActionsProvider::class,\n    ],\n    // ...\n];\n```\n\nAfter that, you should run the following command to publish the configuration file to `config/server-actions.php` and setup other things that might be needed.\n\n```bash\nphp artisan server-actions:install\n```\n\nThen you can use the `useServer` helper function in your Blade templates like:\n\n```php\n\u003c?php\n    // File: /resources/views/my-form.blade.php\n\n    use function DevHammed\\ServerActions\\useServer;\n?\u003e\n\n\u003cform\n    method=\"post\"\n    action=\"\u003c?= useServer(function (string $name) {\n            return 'Hello, ' . $name;\n    }) ?\u003e\"\n\u003e\n    @csrf\n    \u003cinput type=\"hidden\" name=\"name\" value=\"Hammed\"\u003e\n    \u003cbutton type=\"submit\"\u003eGreet the creator\u003c/button\u003e\n\u003c/form\u003e\n```\n\nNote that the `@csrf` directive is required for Laravel to accept the request since this is like\nevery other form request and the handler can be used just like you would use a controller method e.g redirecting, returning a view, etc.\nwhich is why we are returning a string instead of echoing it unlike the vanilla PHP example.\n\nThat's it! Go make some server actions!\n\n## License\n\nThis package is open-sourced software licensed under the [MIT license](LICENSE.md).\n\n## Credits\n\n- [Hammed Oyedele](https://github.com/devhammed)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevhammed%2Fphp-server-actions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevhammed%2Fphp-server-actions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevhammed%2Fphp-server-actions/lists"}