Download the PHP package nathanheffley/laravel-watermelon without Composer

On this page you can find all versions of the php package nathanheffley/laravel-watermelon. 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 laravel-watermelon

Laravel Watermelon

This package provides a Watermelon DB backend sync implementation for Laravel. Watermelon DB is a robust local database synchronization tool to help develop offline-first application. One of the biggest hurdles is implementing the logic on your server to handle the synchronization process.

That's where this package comes in to provide a quick synchronization route you can get up and running in minutes.

This project is still in active development and does not support schema versions or migrations yet. Both of these are major parts of the Watermelon DB spec. Please expect large changes at least until those features are implemented.

Installation

Before getting started you'll need to install the package and publish the config file.

Usage

Once you've installed the package, you need to specify which models will be available through the synchronization endpoint. Open up the config/watermelon.php file and update the models array. The key needs to be the name of table used locally in your application, and the value must be classname of the related model.

You can also change the route to be something other than /sync by editing the config file or setting the WATERMELON_ROUTE environment variable. You will have to ensure your application makes synchronization requests to whatever route you specify.

By default, only your global middleware will be applied to the synchronization endpoint. This means that unless you changed the default global middleware in your Laravel project the synchronization endpoint will be unauthenticated. If you want to have access to the currently authenticated user you will need to add the web middleware to the config file's middleware array. If you want to restrict access to the synchronization endpoint to authenticated users only, you can add the auth middleware in addition to the web middleware. Of course, you can add any middleware you would like as long as it's registered in your project.

Once you've specified which models should be available through the synchronization endpoint, you'll need to implement some functionality in the models to support being served as Watermelon change objects.

You will need to add a database column to all of your models to keep track of what the Watermelon ID is, called watermelon_id. The default IDs generated by Watermelon are alphanumeric strings, although you can change the type of the column if you don't use the default IDs autogenerated by Watermelon. A unique index on the column is recommended, and I like placing it directly after the id column.

If you did not originally include the created_at, updated_at, and deleted_at timestamp columns, you will also need to add those columns. Please refer to the Laravel documentation for implementing the timestamps and soft deleting functionality.

The only thing you must change in your model class is to use the Watermelon trait.

The attributes returned through the synchronization endpoint are whitelisted by default. Out of the box, only the watermelon_id will be returned (although it will be passed through the endpoint as just id, this is intentional). To include more attributes, you will need to add a watermelonAttributes property to your class. These attributes will be included alongside the Watermelon ID and can be updated by change objects posted to the synchronization endpoint.

If you need more control over the attributes returned you can override the entire toWatermelonArray function.

Authorization

By default, all models will be accessible and able to be updated through the synchronization endpoint. This is obviously not ideal in most projects where you need control to authorize which models users can see and what they can update.

Scoping entire records

You can implement a query scope on your models by overriding the scopeWatermelon function. This scope will be applied before returning data to pull requests. This can be used, for example, to restrict records to only be retrievable by users authorized to see them (to have access to the Auth::user() like in this example, don't forget to add the web and auth middlewares as shown in the config example at the start of the Usage section).

Package Development

If you have PHP and Composer installed on your local machine you should be able to easily run the PHPUnit test suite.

If you prefer to run the tests within a Docker container, this project includes Laravel Sail.

To install the dependencies:


All versions of laravel-watermelon with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/database Version ^11.0
illuminate/http Version ^11.0
illuminate/routing Version ^11.0
illuminate/support Version ^11.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 nathanheffley/laravel-watermelon contains the following files

Loading the files please wait ....