Download the PHP package mimachh/slugme without Composer

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

Deux façon de l'utiliser :

Le package ne va pas fournir de migration. Il faudra ajouter la column manuellement

Slugme

Slugme is a simple and efficient Laravel package that helps you automatically generate unique slugs for a specified attribute of your models and store them in the database.

Installation

To install the package via Composer, run the following command:

Usage

Important: Manually Add the slug Column

Please note that the slug column must be manually added in your database migration.

Implement the Sluggable Interface in Your Model

To use this package, you need to implement the Sluggable interface in the model you want to slugify.

Automatically Generate Slugs

Once you’ve implemented the Sluggable interface and used the HasSlug trait, slugs will be automatically generated when creating or updating the model. The package ensures that slugs are unique, even when there are conflicts.

For example, if the title is My First Post, the package will generate a slug like my-first-post. If the slug already exists, it will append a counter (e.g., my-first-post-1).

Update Slugs on Model Updates

If you update the slugAttribute (e.g., title), the package will automatically regenerate and ensure that the slug remains unique.

Custom Slug Logic

You can also customize the slug generation logic by overriding the generateUniqueSlug method in your model if needed.

Example Here's an example of how to create and update a model with slugs:

Generating Unique Slugs without Implementing the Sluggable Interface

If you prefer not to implement the Sluggable interface and want to manually handle slug generation, you can use the SlugGenerator service included with this package. This approach gives you the flexibility to call the slug generation method directly and handle saving it to the database yourself.

1. Using the SlugGenerator Service

The SlugGenerator class allows you to generate unique slugs for any model and attribute, while ensuring the slug is unique, even during model updates.

Here’s how you can use it.

Example of Creating a Slug

In this example, we’ll generate a unique slug for a Post model based on the title attribute.

In this example:

When a new Post is created, the creating event automatically generates a slug using the title attribute. During an update, if the title has been modified, the updating event regenerates the slug while ensuring uniqueness, excluding the current post's ID.

2. Manual Slug Generation

You can also generate slugs manually in your controller or anywhere in your application. This gives you control over when and where slugs are generated and saved.

For updates:

3. Explanation of the SlugGenerator

The SlugGenerator::generateUniqueSlug method takes the following parameters:

Example of a Migration

As mentioned earlier, make sure to add the slug column to your migration, like so:

With this approach, you have full control over slug generation and uniqueness checks, without the need to implement the Sluggable interface or use traits.


All versions of slugme with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version ^11.9
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 mimachh/slugme contains the following files

Loading the files please wait ....