updating user and language models

This commit is contained in:
Brian 2022-12-07 11:42:36 -07:00
parent fdba9f1ae7
commit 64d4d326b7
Signed by: brian
GPG Key ID: DE1A5390A3B84CD8
4 changed files with 9 additions and 7 deletions

View File

@ -42,18 +42,18 @@ class HandleInertiaRequests extends Middleware
*/ */
public function share(Request $request): array public function share(Request $request): array
{ {
$localeFields = ['locale', 'iso_code', 'name', 'localized_name']; $localeFields = ['locale_name', 'iso_code', 'name', 'localized_name'];
$currentLocale = $request->session()->get('locale', null); $currentLocale = $request->session()->get('locale', null);
if (is_null($currentLocale)) { if (is_null($currentLocale)) {
$currentLocale = Language::where(['locale' => 'en', 'iso_code' => 'en_US'])->get($localeFields)[0]->toArray(); $currentLocale = Language::where(['locale_name' => 'en', 'iso_code' => 'en_US'])->get($localeFields)[0]->toArray();
$request->session()->put('locale', [ $request->session()->put('locale', [
'locale' => $currentLocale['locale'], 'locale_name' => $currentLocale['locale_name'],
'iso_code' => $currentLocale['iso_code'], 'iso_code' => $currentLocale['iso_code'],
'name' => $currentLocale['name'], 'name' => $currentLocale['name'],
'localized_name' => $currentLocale['localized_name'], 'localized_name' => $currentLocale['localized_name'],
]); ]);
} }
$localeFilePath = base_path("lang/{$currentLocale['locale']}.json"); $localeFilePath = base_path("lang/{$currentLocale['locale_name']}.json");
$notifications = []; $notifications = [];
$notificationsCount = count($notifications); $notificationsCount = count($notifications);

View File

@ -7,18 +7,20 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Prunable; use Illuminate\Database\Eloquent\Prunable;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class Language extends Model class Language extends Model
{ {
use HasFactory; use HasFactory;
use Prunable; use Prunable;
use SoftDeletes;
/** @var string */ /** @var string */
protected $table = 'languages'; protected $table = 'languages';
/** @var array<int,string> */ /** @var array<int,string> */
protected $fillable = [ protected $fillable = [
'locale', 'locale_name',
'iso_code', 'iso_code',
'name', 'name',
'localized_name', 'localized_name',

View File

@ -32,7 +32,7 @@ class UserFactory extends Factory
'email' => $this->faker->unique()->safeEmail(), 'email' => $this->faker->unique()->safeEmail(),
'email_verified_at' => now(), 'email_verified_at' => now(),
'timezone_name' => $this->faker->timezone(), 'timezone_name' => $this->faker->timezone(),
'timezone_name' => Language::all()->random()->id, 'language_id' => Language::all()->random()->id,
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10), 'remember_token' => Str::random(10),
]; ];

View File

@ -15,7 +15,7 @@ return new class extends Migration
{ {
Schema::create('languages', function (Blueprint $table) { Schema::create('languages', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('locale')->index(); $table->string('locale_name')->index();
$table->string('iso_code')->unique(); $table->string('iso_code')->unique();
$table->string('name'); $table->string('name');
$table->string('localized_name'); $table->string('localized_name');