環境:
Laravel@9.52.4
migrate 済みの migration ファイルを削除してしまい、php artisan migrate:reset で Migration not found とエラーが出てしまった場合。
solution)
php artisan migrate:fresh
>>> DB全てのテーブルが削除された後、migrate する処理
ref:
seeder の namespace が間違っていた
seeder を編集しても適用されない場合があるので編集したら composer dump-autoload
環境:
laravel@8.83.23
事象:
Model を soft-delete し、その後 restore 時に特定の処理をしたいが処理が実行されない。
cannot works:
@models/User.php
protected static fucntion boot() {
parent::boot();
static::deleted(function ($user) {
$user->profileDetail()->delete(); // works fine
})
static::updated(function ($user) {
$user->name = "updated";
$user->save(); // works fine
})
static::restored(function ($user) {
$user->profileDetail()->restore(); // cannot works ????
})
}
原因:
User を restore するときに 一意の model を指定していなかったため
User::where('id', $request->id)->withTrashed()->restore(); // requested user will be restore but cannot trigger static::restored(function ($user))
solution)
User::where('id', $request->id)->withTrashed()->first()->restore();
環境:
laravel@8.83.23
jensseger/laravel-mongodb@3.8.0
Model Structure
Profile: {
roles: [’admin’]
}
$profile = App\Profile::find(1);
$profile->roles = array_push($profile->roles, 'superAdmin')
>>> error: Indirect modification of overloaded property App\Profile
solution)
値を編集するのではなく、新たな値を定義する
$roles = array_values($profile->roles)
array_push($roles, 'superAdmin')
$profile->roles = $roles
$profile->save()
http request で得た値をprops として子component にパスした時、mounted で値を加工しようとしたらprops の取得タイミングの都合で正しいprops の値を取得しないで処理されてしまうエラーの回避。さらにその値を編集したい場合。
環境:
vue@2.6.12
@親コンポーネント
axios.get(****).then((res) => {
this.forChildComponent = res.data
})
<some-childComponent :forChildComponent=forChildComponent>
@子コンポーネント
props: ['forChildComponent']
created や mounted で値に操作しようとすると http request のレスポンスによって値が正しく取得できるか左右する
** ダメなケース
mounted() {
this.targetValue = this.forChildComponent + 1
}
>>>> http request のレスポンスが遅いと undefined + 1 になってしまう
** Need fix
computed: {
targetValue() {
return this.forChildComponent + 1
}
}
>>> 値は正しく取得できる。targetValue に追加処理が発生しないのならこれでOK
** Solution さらにforChildComponent を編集する必要がある場合
data() {
return {
newValue: ''
}
},
computed: {
targetValue() {
if(newValue) {
return newValue
} else {
return this.forChildComponent + 1
}
}
},
methods: {
changeTargetValue() {
this.newValue = 9
}
}
直接 props を編集しようとすると
[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders.
とエラーが出るので新たに newValue を設定してエラーを回避
環境:
vuetify@2.6.6
<v-badge color="primary red--text font-weight-bold">
primary >>> バッジ自体のカラー
red--text >>> バッジ内のテキストカラー