Support the ongoing development of Laravel.io →
posted 9 years ago
Database
Last updated 1 year ago.
0

I'm guessing you don't have slugs set on older DB entries yet. Try creating a script that will loop through all of them, adding the slug value, which you probably get from the title.

I don't know the plugin, but Laravel already has support for that.

Str::slug($post->title, '-')

You should probably check that you don't get duplicate values.

Last updated 1 year ago.
0

i think eloquent updating might not work if you have set a validation rule 'unique' for one or more of fields

if that, you should rewrite rules before updating to be: either remove unique rules or add unique exception id as the third argument for unique rule

assume your validation rules like this

$rules = array(
'name' => 'required|unique:test_table,test_column'
);

// while updating assume name doesn't changed and other fields has changed
// since name is unique, eloquent will query if test_column in test_table has the value of name
// since it's already exists while updating, validation will fails so updating fails

// so before updating you should rewrite validation rules to be either

$rules = array(
'name' => 'required'     // By Removing Unique rule
);

// or
$rules = array(
'name' => 'required|unique:test_table,test_column,id'   // or by adding current model id to be as exception for unique rule
);


Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

eugael eugael Joined 25 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.