Download the PHP package khalyomede/laravel-eloquent-uuid-slug without Composer

On this page you can find all versions of the php package khalyomede/laravel-eloquent-uuid-slug. 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-eloquent-uuid-slug

Laravel Eloquent UUID slug

Summary

About

By default, when getting a model from a controller using Route Model Binding, Laravel will try to find a model using the parameter in your route, and associate it to the default identifier of the related table (most of the time, this is the "id" key).

This means if you offer the possibility to view your cart, you will expose the route /cart/12 for example. This is not ideal in terms of security because you now expose your cart database identifier, and if you forgot or made a mistake into your cart's policy, a malicious user can access the cart of other users (/cart/41).

In this context UUID are very useful because:

The best scenarios would be to expose this uuid instead of your database auto incremented identifier, like /cart/e22b86bcb8e24cfea13856a0766bfef2.

The goal of this package is to simplify at best this task for you.

Features

Requirements

Installation

1. Install the package

2. Setup your model

On the model of your choice, use the Sluggable trait.

3. Add the slug column in your migration

The Sluggable trait offers the method Sluggable::addSlugColumn() to make this step a breeze for you.

If you do not want the Sluggable::addSlugColumn(Blueprint) to add SQL constraints (unique index and non nullable column), use its counterpart method Sluggable::addUnconstrainedSlugColumn(Blueprint).

Examples

1. Configure the slug column name

By default the Sluggable trait will assume the name of the slug column is slug. Here is how to provide one that you prefer.

2. Use dashes for the generated UUID

By default, the Sluggable trait will configure the UUID generator to remove dashes, to help make shorter URLs. If you prefer to keep them, here is how you can do it.

3. Custom route model binding for specific routes

By default, all your models that use the Sluggable trait will retreive their model using the slug column when performing Route Model Binding.

If you would like to bypass it for specific routes, you can customize the column used to retreive your model occasionally.

For example, this is how to retreive your Cart model using its id for a specific route.

As a final resort, if this method does not work, you can always fallback to get the raw data from your route, and perform fetching your model yourself:

4. Customize the slug column in your migration

You can use all the available column modifiers right after calling the method Sluggable::addSlugColumn(), to re-order the column or add some comments for example.

5. Retreive a model by its slug

To help you manually fetching a model by its slug, you can use the Sluggable::scopeWithSlug() scope to do it. It follows your configuration, so no matter how you named your slug column it will still work.

The Sluggable::findBySlug(), Sluggable::findBySlugOrFail(), Sluggable::firstBySlug() or Sluggable::firstBySlugOrFail() methods also exist as a shorthand:

6. Dropping the slug column

You can use Sluggable::dropSlugColumn(Blueprint) when you want to drop only the slug column on an existing table. Please follow the complete instructions on the "down" method since there is some gotchas to deal with.

7. Validate a value exists by slug

You can validate a model exists by the slug column you defined. This is equivalent to calling the existing "exists" rule:

But without having to manually specify the slug column (it is fetched automatically according to wether you customized the name or not).

Compatibility table

The table below shows the compatibility across Laravel, PHP and this package current version. For the compatibility regarding this package previous version, please browse another tag.

Laravel version PHP version Compatible
10.* 8.3.*
10.* 8.2.*
10.* 8.1.*
9.* 8.2.*
9.* 8.1.*
9.* 8.0.*
8.* 8.2.*
8.* 8.1.*
8.* 8.0.*
8.* 7.4.*
8.* 7.3.*
7.x *

To counter-check these results, you can use the Docker containers (see docker-compose.yml file) to run the tests described in the Tests section.

Alternatives

I created this package mostly to practice creating a tested laravel package, and toying with my first Github Workflow. There is some others high quality packages out there so make sure to take a look at them!

Tests

Or


All versions of laravel-eloquent-uuid-slug with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2.0
laravel/framework Version 11.*
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 khalyomede/laravel-eloquent-uuid-slug contains the following files

Loading the files please wait ....