Updates About Field Default

Updates the about column to have a default of an empty string. Curse you, MySQL!
This commit is contained in:
Refringe 2024-09-24 00:46:44 -04:00
parent 6bc02ca210
commit 4e33dd9ec5
Signed by: Refringe
SSH Key Fingerprint: SHA256:t865XsQpfTeqPRBMN2G6+N8wlDjkgUCZF3WGW6O9N/k
2 changed files with 20 additions and 1 deletions

View File

@ -8,6 +8,7 @@ use App\Notifications\VerifyEmail;
use App\Traits\HasCoverPhoto;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
@ -209,6 +210,24 @@ class User extends Authenticatable implements MustVerifyEmail
return $filters->apply($builder);
}
/**
* Handle the about default value if empty. Thanks MySQL!
*/
protected function about(): Attribute
{
return Attribute::make(
set: function ($value) {
// MySQL will not allow you to set a default value of an empty string for a (LONG)TEXT column. *le sigh*
// NULL is the default. If NULL is saved, we'll swap it out for an empty string.
if (is_null($value)) {
return '';
}
return $value;
},
);
}
/**
* Get the disk that profile photos should be stored on.
*/

View File

@ -22,7 +22,7 @@ return new class extends Migration
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->longText('about');
$table->longText('about')->nullable()->default(null);
$table->foreignIdFor(UserRole::class)
->nullable()
->default(null)