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 :: add text to image and save php 
Php :: laravel required_if 
Php :: compare php date with mysql date 
Php :: remove empty array elements php 
Php :: php if 
Php :: date diff in laravel 
Php :: date time laravel 
Php :: php mysql prepare query 
Php :: env value return null laravel 
Php :: laravel validation get failed rules 
Php :: calculate days of a month 
Php :: symfony change php version 
Php :: destory session in laravel 
Php :: Create Model with Controller in Laravel 
Php :: php get day of week 
Php :: this page isn t working http error 500 laravel on server 
Php :: do i need to install php after xampp 
Php :: laravel migration update table column type 
Php :: laravel add user 
Php :: php set status code 
Php :: add text next to price woocommerce 
Php :: laravel display old value 
Php :: type casting in php 
Php :: php remove control characters from string 
Php :: Malformed UTF-8 characters, possibly incorrectly encoded 
Php :: give custom field name in laravel form validation error message 
Php :: mysqli_test 
Php :: carbon get day name 
Php :: Delete quotes in php 
Php :: laravel where 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =