Download the PHP package putyourlightson/laravel-datastar without Composer

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

Total Downloads

Datastar Package for Laravel

A reactive hypermedia framework for Laravel.

[!WARNING] This package is in beta and its API may change.

This package integrates the Datastar hypermedia framework with Laravel, allowing you to create reactive frontends driven by Blade views or controllers. It aims to replace the need for front-end frameworks such as React, Vue.js and Alpine.js + htmx, and instead lets you manage state and use logic from your Laravel backend.

Use-cases:

License

This package is licensed for free under the MIT License.

Requirements

This package requires Laravel 11.0.0 or later.

Installation

Install manually using composer, then run the artisan vendor:publish --tag=public command to publish the public assets.

Overview

The Datastar package for Laravel allows you to handle backend requests by sending SSE events using using controllers. The former requires less setup and is more straightforward, while the latter provides more flexibility.

Here’s a trivial example that toggles some backend state using the Blade view datastar/toggle.blade.php to handle the request.

Usage

Start by reading the Getting Started guide to learn how to use Datastar on the frontend. The Datastar package for Laravel only handles backend requests.

[!NOTE] The Datastar VSCode extension and IntelliJ plugin have autocomplete for all data-* attributes.

When working with signals, note that you can convert a PHP array into a JSON object using the json_encode function.

Datastar Helper

The datastar() helper function is available in Blade views and returns a Datastar helper that can be used to generate action requests to the Datastar controller. The Datastar controller renders a view containing one or Signals are also sent as part of the request, and are made available in Datastar views using the $signals variable.

datastar()->get()

Returns a @get() action request to render a view at the given path. The value can be a file path or a dot-separated path to a Blade view.

Variables can be passed into the view using a second argument. Any variables passed in will become available in the rendered view. Variables are tamper-proof yet visible in the source code in plain text, so you should avoid passing in any sensitive data.

datastar()->post()

Works the same as datastar()->get() but returns a @post() action request to render a view at the given path. A CSRF token is automatically generated and sent along with the request.

datastar()->put()

Works the same as datastar()->post() but returns a @put() action request.

datastar()->patch()

Works the same as datastar()->post() but returns a @patch() action request.

datastar()->delete()

Works the same as datastar()->post() but returns a @delete() action request.

datastar()->getFragments()

Returns a @get() action request to render and automatically merge the fragments contained in a view at the given path. The view should contain one or more fragments to be merged.

Blade Directives

@mergefragments

Merges one or more fragments into the DOM.

@removefragments

Removes one or more HTML fragments that match the provided selector from the DOM.

@mergesignals

Updates the signals with new values.

@removesignals

Removes signals that match one or more provided paths.

@executescript

Executes JavaScript in the browser.

@location

Redirects the browser by setting the location to the provided URI.

Using Controllers

You can send SSE events using your own controller instead of the Datastar controller by using the DatastarEventStream trait. Return the getStreamedResponse() method, passing a callable into it that sends zero or more SSE events using methods provided.

DatastarEventStream Trait

mergeFragments()

Merges one or more fragments into the DOM.

removeFragments()

Removes one or more HTML fragments that match the provided selector from the DOM.

mergeSignals()

Updates the signals with new values.

removeSignals()

Removes signals that match one or more provided paths.

executeScript()

Executes JavaScript in the browser.

location()

Redirects the browser by setting the location to the provided URI.

renderDatastarView()

Renders a Datastar view.

Signals

When working with signals, either in views rendered by the Datastar controller or by calling $this->getSignals(), you are working with a Signals model, which provides a simple way to manage signals.

[!NOTE] Signals updates cannot be wrapped in {% mergefragment %} tags, since each update creates a server-sent event which will conflict with the fragment’s contents.


Created by PutYourLightsOn.


All versions of laravel-datastar with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
laravel/framework Version ^11.0
starfederation/datastar-php Version 1.0.0-beta.17
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 putyourlightson/laravel-datastar contains the following files

Loading the files please wait ....