samedi 28 mars 2020

Dynamic seeding in laravel 5.4

I'm extremely new to laravel and having trouble with this seeder. I feel like it should be an easy thing to do, I just don't have the right tools for it yet.

I need to populate a column with data based on a different column. More specifically, I want to take the employee_id, find where their location is in the employee table, and populate that id in the application table. This is what I have so far:


use Illuminate\Database\Seeder;

use App\Employee;
use App\Application;


class ApplicationEmployeeLocationTableSeeder extends Seeder 
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $applications= Application::all();

        foreach ($applications as $application)
        {
            $location_id = Employee::whereId($application->employee_id)->pluck('location_id')->first();
        }

    }

}

This returns all the ids I'm looking for as a string, but how do I put these values into location_idin the applications table? Running this seeder doesn't produce an error, but it doesn't do anything either.

Let me know if there's any other information you need, and thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire