Download the PHP package zschuessler/laravel-route-to-class without Composer

On this page you can find all versions of the php package zschuessler/laravel-route-to-class. 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-route-to-class

Alt text

Dynamic Body Classes for Laravel

Quickly add body classes to your Laravel app based on rules you set.

Example of implementations:

  1. Browsing as a guest might add user-isGuest as a class.
  2. Browsing an admin panel might add admin-panel as a class.
  3. All user profile routes might have user-profile as a class.

It's easy to write your own rules! You can either write your own generator classes or use the ad-hoc API by interacting with the library singleton directly.

Quickstart

Require the package in your composer setup.

Publish the configuration file

Run the following command in the root directory of your project:

Use In Layout

You can either use the included Blade directive, or access the Route2Class facade directly for outputting your classes.

Blade

Two important notes for using the Blade directive:

  1. The Blade directive will follow any caching solutions you have setup. This is great for production, but keep in mind on development you may be viewing cached classes when modifying generators.
  2. The Blade directive runs before all other view template code. As such, any calls to the Route2Class package in a view will not show up in your class list.

Facade

Facades are not cached in the manner Blade directives are, making them great for development environments. And because we aren't using a Blade directive, you can modify classes and generators within view templates too.

Use it in any of your views like so:

Implement Your Own Rules

You can implement your own rules in one of two methods.

Create Generator File

This is the preferred method since you will always know where your class modifiers ( called generators) will live.

First decide where you would like to keep your generators. For the purpose of this example we will use the following directory:

app/Providers/RouteToClass/UserTypeGenerator.php

All you have to do is extend the GeneratorAbstract.php file and implement a method which returns the class string. See below for a simple example:

Next add a reference to the generator in your /config/route2class.php configuration:

Now when you call the facade or Blade directive in a view template, you will see the class user-admin - neat!

See this file for a real-life generator example:

https://github.com/zschuessler/laravel-route-to-class/blob/master/src/Generators/FullRoutePath.php

Ad-Hoc Class Additions

You can interact with the body classes directly by calling the addClass method on the provider.

Here's an example using the default Laravel project's routes file:

You can call the addClass method anywhere - models, controllers, etc. Consider adding generator files instead, as it promotes application maintainability and reduces technical debt.

Demo Project

The demo project below follows the examples outlined above:

https://github.com/zschuessler/route2class-demo

License

This is public domain. Do what you want.


All versions of laravel-route-to-class with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version 5.3.*||5.4.*||5.5.*||5.6.*||5.7.*||5.8.*||^6.0||^7.0||^8.0||^9.0||^10.0 || ^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 zschuessler/laravel-route-to-class contains the following files

Loading the files please wait ....