Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```php
- Route::get('/create', function() {
- Topic::forceCreate([
- 'title' => 'This is a title',
- 'slug' => str_slug('This is a title')
- ]);
- });
- ```
- ```php
- Route::get('/create', function() {
- Topic::find(2)->update([
- 'title' => 'This is another title',
- 'slug' => str_slug('This is another title')
- ]);
- });
- ```
- ```php
- class Topic extends Model
- {
- public static function boot()
- {
- parent::boot();
- static::creating(function ($topic) {
- $topic->slug = str_slug($topic->titlejjj);
- });
- static::updating(function ($topic) {
- $topic->slug = str_slug($topic->titlejjj);
- });
- }
- }
- ```
- Now
- ```php
- Route::get('/create', function() {
- Topic::forceCreate([
- 'title' => 'This is a title'
- ]);
- });
- ```
- ```php
- Route::get('/create', function() {
- Topic::find(2)->update([
- 'title' => 'This is another title'
- ]);
- });
- ```
Add Comment
Please, Sign In to add comment