How update name field in migrations

Published 1 week ago by mstdmstd

Hello, If there is a way in migrations to update name field of the table. I had a seeder like:

        \App\Models\StorageSpaceStatus::insert(
            [
                ['id' => 1, 'name' => 'Available',      'color' => '#FFA500'],
                ['id' => 2, 'name' => 'Booked',         'color' => '#008000'],
            ]
        );

Now I need to modify name of the

'name' = 'Booked'

Which is the valid way to do it?

laravel 5.5

Thanks!

Best Answer (As Selected By mstdmstd)
Cronix

@mstdmstd

StorageSpaceStatus::where('name', 'Booked')->update(['name' => 'OTHER VALUE']);
BishoyWagih

you can create another migration to update this column..

php artisan make:migration update_storage_space_status_name_field --

    table="table-name";

then you can do..

Schema::table('table-name', function (Blueprint $table) {
     $table->string('name', 'new name')->change();
});

check documentation..

https://laravel.com/docs/5.6/migrations#modifying-columns

mstdmstd

Sorry, if I put my questions in poor way. I do not need to modify structure of the table, but some key value. I mean that I had a seeder, which set value of some field by seeder :

\App\Models\StorageSpaceStatus::insert(
            [
                ['id' => 2, 'name' => 'Booked',         'color' => '#008000'],
            ]
        );

Now I need to modify name field with other value and I did not find update method(similar insert above). I want to generate sql like:

UPDATE storage_space_statuses SET name='OTHER VALUE' where name = ‘Booked’

Thanks!

Cronix
Cronix
1 week ago (566,300 XP)

@mstdmstd

StorageSpaceStatus::where('name', 'Booked')->update(['name' => 'OTHER VALUE']);
Snapey
Snapey
1 week ago (926,225 XP)

edit your seeder and rerun it?

Otherwise, as cronix says, its just an Eloquent or DB update

Please sign in or create an account to participate in this conversation.