Guest User

Untitled

a guest
Jun 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. ```php
  2. Route::get('/create', function() {
  3. Topic::forceCreate([
  4. 'title' => 'This is a title',
  5. 'slug' => str_slug('This is a title')
  6. ]);
  7. });
  8. ```
  9.  
  10. ```php
  11. Route::get('/create', function() {
  12. Topic::find(2)->update([
  13. 'title' => 'This is another title',
  14. 'slug' => str_slug('This is another title')
  15. ]);
  16. });
  17. ```
  18.  
  19.  
  20. ```php
  21. class Topic extends Model
  22. {
  23. public static function boot()
  24. {
  25. parent::boot();
  26.  
  27. static::creating(function ($topic) {
  28. $topic->slug = str_slug($topic->titlejjj);
  29. });
  30.  
  31. static::updating(function ($topic) {
  32. $topic->slug = str_slug($topic->titlejjj);
  33. });
  34. }
  35. }
  36. ```
  37.  
  38. Now
  39.  
  40. ```php
  41. Route::get('/create', function() {
  42. Topic::forceCreate([
  43. 'title' => 'This is a title'
  44. ]);
  45. });
  46. ```
  47.  
  48. ```php
  49. Route::get('/create', function() {
  50. Topic::find(2)->update([
  51. 'title' => 'This is another title'
  52. ]);
  53. });
  54. ```
Add Comment
Please, Sign In to add comment