Download the PHP package devhammed/server-actions without Composer
On this page you can find all versions of the php package devhammed/server-actions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download devhammed/server-actions
More information about devhammed/server-actions
Files in devhammed/server-actions
Package server-actions
Short Description PHP server actions!
License MIT
Homepage https://github.com/devhammed/php-server-actions
Informations about the package server-actions
devhammed/server-actions
Making Next.js Server Actions work in PHP!
This is a proof of concept inspired by this tweet, and it's not meant to be used in production.
But it works so let's go!
Installation
The recommended way to install this package is through Composer.
Then include the Composer autoloader in your entry file (e.g index.php
) like:
But you can also download this repository and include the provided autoload.php
file e.g
Usage
You can use this package in any PHP project, but it has first-class support for Laravel and all the heavy lifting is done for you.
You can skip to the Laravel section if you are using Laravel.
The 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
without 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
DevHammed\ServerActions\Contracts\ServerEntry interface.
Then you need to create the server actions handler file that was specified in the withServerActionsUrl
method e.g server-actions.php
that will look
almost the same as the entry file but with the run()
method called at the end of the chain and nothing else, like:
Then you can use the useServer
helper function in the included PHP files like:
Laravel
This package provides a service provider for Laravel that will automatically initialize the server and endpoint for you.
You 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.
After 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.
Then you can use the useServer
helper function in your Blade templates like:
Note that the @csrf
directive is required for Laravel to accept the request since this is like
every other form request and the handler can be used just like you would use a controller method e.g redirecting, returning a view, etc.
which is why we are returning a string instead of echoing it unlike the vanilla PHP example.
That's it! Go make some server actions!
License
This package is open-sourced software licensed under the MIT license.
Credits
All versions of server-actions with dependencies
opis/closure Version ^3.6
ramsey/uuid Version ^4.7
illuminate/contracts Version ^10.0
spatie/laravel-package-tools Version ^1.16
illuminate/support Version ^10.0