Download the PHP package rafaelwendel/phpsupabase without Composer

On this page you can find all versions of the php package rafaelwendel/phpsupabase. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phpsupabase

PHPSupabase

PHPSupabase is a library written in php language, which allows you to use the resources of a project created in Supabase (supabase.io), through integration with its Rest API.

Content

About Supabase

Supabase is "The Open Source Firebase Alternative". Through it, is possible to create a backend in less than 2 minutes. Start your project with a Postgres Database, Authentication, instant APIs, realtime subscriptions and Storage.

PHPSupabase Features

Instalation & loading

PHPSupabase is available on Packagist, and instalation via Composer is the recommended way to install it. Add the follow line to your composer.json file:

or run

How to use

To use the PHPSupabse library you must have an account and a project created in the Supabase panel. In the project settings (API section), you should note down your project's API key and URL. (NOTE: Basically we have 2 suffixes to use with the url: /rest/v1 & /auth/v1, but since version 0.0.5 the definition of one of these suffixes is optional)

To start, let's instantiate the Service() class. We must pass the API key and url in the constructor

The Service class abstracts the actions with the project's API and also provides the instances of the other classes (Auth, Database and QueryBuilder).

Auth class

Let's instantiate an object of the Auth class

The $auth object has several methods for managing project users. Through it, it is possible, for example, to create new users or even validate the sign in of an existing user.

Create a new user with email and password

See how to create a new user with email and password.

This newly created user is now in the project's user table and can be seen in the "Authentication" section of the Supabase panel. To be enabled, the user must access the confirmation link sent to the email.

In the third parameter of the createUserWithEmailAndPassword method you can pass an array containing the user_metadata to be saved (Ex: name and age)

Sign in with email and password

Now let's see how to authenticate a user. The Authentication request returns a access_token (Bearer Token) that can be used later for other actions and also checks expiration time. In addition, other information such as refresh_token and user data are also returned. Invalid login credentials result in throwing a new exception

Get the data of the logged in user

To get the user data, you need to have the access_token (Bearer Token), which was returned in the login action.

Update user data

It is possible to update user data (such as email and password) and also create/update metadata, which are additional data that we can create (such as first_name, last_name, instagram_account or any other).

The updateUser method must take the bearerToken as argument. In addition to it, we have three more optional parameters, which are: email, password and data (array). If you don't want to change some of this data, just set it to null.

An example of how to save/update two new meta data (first_name and last_name) for the user.

Note that in the array returned now, the keys first_name and last_name were added to user_metadata.

Database class

The Database class provides features to perform actions (insert, update, delete and fetch) on the Postgre database tables provided by the Supabase project.

For the samples below, consider the following database structure:

The Database class is also instantiated from the service object. You must pass the table that will be used and its respective primary key (usually id).

Let's create an object to work with the categories table:

Through the db variable it is possible to perform the actions on the categories table.

NOTE: If Row Level Security (RLS) is enabled in the used table, pass the bearerToken to the Service object:

Insert data

Inserting a new record in the categories table:

Now let's insert a new product from category 1 - Video Games:

Update data

To update a record in the database, we use the update method, passing as parameter the id (PK) of the record to be updated and an array containing the new data (NOTE: For now, it is not possible to perform an update using a parameter other than the primary key).

In the example below, we will update the productname and price of the product with id=1 ("Xbox Series S" to "XBOX Series S 512GB" and "299.99" to "319.99"):

Delete data

To delete a record from the table, just call the delete method and pass the id (PK) of the record to be deleted as a parameter.

The following code deletes the product of id=1 in the products table:

Fetch data

The following methods for fetching data are available in the Database class:

All the mentioned methods return the self instance of Database class. To access the fetched data, call the getResult method.

See some examples:

Now, an example using the findBy method:

Searching for products and adding a join with the categories table:

An example of a custom query to search id,productname,price for all products "JOIN" categories filtering by price (price greater than 200.00):

Other examples for custom query:

Comparison operators

The main operators available for the where clause:

Other operators available:

QueryBuilder class

The QueryBuilder class provides methods for dynamically building SQL queries. It is instantiated from the service object.

NOTE: If Row Level Security (RLS) is enabled on any of the tables used, pass the bearerToken to the Service object:

Available methods:

All the mentioned methods return the self instance of QueryBuilder class. To run the mounted query, call the execute method. Then, to access the fetched data, call the getResult method.

An example to fetch all data from the products table:

An example to fetch all data from the products "JOIN" categories:

Fetch products with categoryid=1 and price>200 order by price:

Some of the operators to be used in the where method can be seen in the Comparison operators section.


All versions of phpsupabase with dependencies

PHP Build Version
Package Version
Requires guzzlehttp/guzzle Version ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rafaelwendel/phpsupabase contains the following files

Loading the files please wait ....