読み込みが終了しない場合は、しばらく待つか、リロードを行なってください。
If loading does not finish, wait for a while or reload.
エンジニア向けの情報を発信するブログです。
どなたでも発信できます。
お好きに利用していただれば幸いです。
php artisan make:observer TestObserver --model=Article
📁 App/Observers/TestObserver.php <?php namespace App\Observers; use App\Article; class TestObserver { /** * Handle the article "created" event. * * @param \App\Article $article * @return void */ public function created(Article $article) { // } /** * Handle the article "updated" event. * * @param \App\Article $article * @return void */ public function updated(Article $article) { // } /** * Handle the article "deleted" event. * * @param \App\Article $article * @return void */ public function deleted(Article $article) { // } /** * Handle the article "restored" event. * * @param \App\Article $article * @return void */ public function restored(Article $article) { // } /** * Handle the article "force deleted" event. * * @param \App\Article $article * @return void */ public function forceDeleted(Article $article) { // } }
//~~省略 use App\Article; //~~省略 public function creating(Article $article) { // } public function updating(Article $article) { // }
📁 App/Providers/AppServicePrivider.php //~省略 use App\Article; //~省略 /** * Bootstrap any application services. * * @return void */ public function boot() { //↓追加 Article::observe(\App\Observers\TestObserver::class); }
public function creating(Article $article) { $article->title = 'creating!'; }
//~~省略 public function updating(Article $article) { $article->title = 'updating!'; }
<?php namespace App; use Illuminate\Database\Eloquent\Model; class Article extends Model { //~~省略 public static function boot() { parent::boot(); } }
public static function boot() { parent::boot(); self::creating(function (self $article) { $article->title = 'model_creating'; }); }
public static function boot() { parent::boot(); self::creating(function (self $article) { $article->title = 'model_creating'; }); self::updating(function (self $article) { $article->title = 'model_updating'; }); }