“Laravel generuje ślimak” Kod odpowiedzi

Laravel generuje ślimak

<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Support\Str;

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

Wygeneruj ślimaka na utworzeniu 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']);

Bug Killer

Jak stworzyć ślimak w Laravel

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

Laravel Slug

php artisan vendor:publish --provider="Cviebrock\EloquentSluggable\ServiceProvider"
Cooperative Caracal

Odpowiedzi podobne do “Laravel generuje ślimak”

Pytania podobne do “Laravel generuje ślimak”

Więcej pokrewnych odpowiedzi na “Laravel generuje ślimak” w PHP

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu