Eloquent-sluggable build_from being ignored

I have a class called Vara where I have a table field called searchname. I want to make a simple cviebrock eloquent sluggable setup, but can't figure out what the problem is.

When I save my model nothing happens, it overwrites the old value.

If I change build_from to whatthefuckisgoingon I get the same output. I have a field called handle, also tried to change the namne field to slug, but the same result. If I leave build_from blank, I also get the same result.

If I however change save_to to something that does not exist, I get an error. The search name field is set to "HjordnΓ€ra test 33 liter", so the output is really simple.

I am assuming that build_from is ignored and treated as null. How to fix it?

My Vara.php looks like this

use Cviebrock\EloquentSluggable\SluggableInterface;
use Cviebrock\EloquentSluggable\SluggableTrait;

class Vara extends \Eloquent implements SluggableInterface {

use SluggableTrait;

protected $sluggable = array(
    'build_from' => 'searchname',
    'save_to'    => 'handle'
);

      

In my VarorController.php

public function saveVara() 
{

    $id = Input::get('id');

    $vara = Vara::find(Input::get('id'));

    $vara->edited_by = Auth::user()->id;

    $vara->searchname        = Input::get('searchname');
    $vara->save();

    return $vara->getSlug();

      

Ok a litle update, found this function in SluggableTrait.php

public function sluggify($force=false)
    {
        $config = \App::make('config')->get('eloquent-sluggable::config');
        $this->sluggable = array_merge( $config, $this->sluggable );
        if ($force || $this->needsSlugging())
        {
            $source = $this->getSlugSource();
            $slug = $this->generateSlug($source);
            $slug = $this->validateSlug($slug);
            $slug = $this->makeSlugUnique($slug);
            $this->setSlug($slug);
        }
        return $this;
    }

      

so if i add $ vara-> sluggify (true); for my controller the pool is being saved so now the questions are why it doesn't automatically fail on $ vara-> save ();

+3


source to share


1 answer


This is most likely a validation question because you are using Ardent :

Ardent is a package that "provides self-asserting smart models for the Laravel Framework 4 Eloquent ORM"

Check your rules and use the operator if

:

if(! $vara->save()) // if model is invalid
    dd($vara->errors());

      



If you don't need to check validation, you can use

$vara->forceSave();

      

To integrate Eloquent sluggable with Ardent take a look at the link

0


source







All Articles