1- Error 1071
AppServiceProvider.php
file and inside the boot
method set a default string length:use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
2- CSRF Protection
<form method="POST" action="/profile">
{{ csrf_field() }}
...
</form>
3- Change from link to submit
<form id="my_form" action="/profile" method="POST">
{{ csrf_field() }}
<!-- Your Form -->
<a href="javascript:{}" onclick="document.getElementById('my_form').submit(); return false;">submit</a>
</form>
3- Slug
- Install the package via Composer:
$ composer require cviebrock/eloquent-sluggable
The package will automatically register itself. - Optionally, publish the configuration file if you want to change any defaults:
php artisan vendor:publish --provider="Cviebrock\EloquentSluggable\ServiceProvider"
Updating your Eloquent Models
Your models should use the Sluggable trait, which has an abstract method
sluggable()
that you need to define. This is where any model-specific configuration is set (see Configuration below for details):use Cviebrock\EloquentSluggable\Sluggable;
class Post extends Model
{
use Sluggable;
/**
* Return the sluggable configuration array for this model.
*
* @return array
*/
public function sluggable()
{
return [
'slug' => [
'source' => 'title'
]
];
}
}
Next, add your new provider to the
providers
array of config/app.php
: 'providers' => [
// ...
Cviebrock\EloquentSluggable\ServiceProvider::class,
// ...
],
Update: $post->slug = null;