Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel generate slug

<?php

namespace AppHttpControllersAdmin;

use AppHttpControllersController;
use IlluminateSupportStr;

class SlugController extends Controller
{
    public function show()
    {
        $slug = [
            Str::slug('Laravel 5 Framework', '-'),
            Str::slug('артел модеб 65 маркаси', '-'),
            Str::slug('Namangan viloyati ', '-'),
            ];
        return $slug;
    }
}
Comment

how to create slug in laravel

public function setTitleAttribute($value)
{
    $this->attributes['title'] = $value;
    $this->attributes['slug'] = str_slug($value);
}
Comment

generate slug on create laravel

/**
 * Laravel provides a boot method which is 'a convenient place to 
 * register your event bindings.'
 * See: https://laravel.com/docs/master/eloquent#events
 */
public static function boot()
{
    parent::boot();

    // registering a callback to be executed upon the creation of an activity AR
    static::creating(function($activity) {

        // produce a slug based on the activity title
        $slug = Str::slug($news->title);

        // check to see if any other slugs exist that are the same & count them
        $count = static::whereRaw("slug RLIKE '^{$slug}(-[0-9]+)?$'")->count();

        // if other slugs exist that are the same, append the count to the slug
        $activity->slug = $count ? "{$slug}-{$count}" : $slug;

    });

}
// Use the create method
Activity::create(['title'=>'lorem ipsum']);

Comment

PREVIOUS NEXT
Code Example
Php :: highlight search text in php 
Php :: replace _ with space php 
Php :: php time how long a function takes 
Php :: php utf 8 sqlsrv 
Php :: How to change add to cart button in wordpress 
Php :: get hours difference between two dates in php 
Php :: php redirect if not logged in 
Php :: php get myme type of image 
Php :: group_concat laravel 
Php :: php truncate string 
Php :: unique value when two columns laravel migration 
Php :: foreach comma separated string php 
Php :: Check duplicate email using Jquery validation 
Php :: wordpress define constant if not defined 
Php :: laravel enum migration 
Php :: wordpress custom fields variable dump 
Php :: group users on country vice in laravel 
Php :: excerpt length wordpress 
Php :: php reset mysql array 
Php :: twig dd 
Php :: strupper php 
Php :: php random float number with 2 decimal places 
Php :: remove html from string php 
Php :: enable shortcodes in text widgets 
Php :: print value in laravel console 
Php :: trim elements of array php 
Php :: php get end date of month 
Php :: laravel pass parameter to resource collection 
Php :: acf get sub field 
Php :: php remove wordpress shortcodes 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =