database/seeds/UserSeeder.php
/**
     * Run the database seeds.
     *
     * @return void
     */
Run the database seeds.
@return void
Run the database seeds . @return void
public function run()
    {
        /*con contructor laravel
        //$professions = DB::table('professions')->select('id')->take(1)->get();
        //para obtener un solo resultado y que no traiga la coleccion completa
        $professions = DB::table('professions')->select('id')->first();
        //Pasar mas argumentos
        $professions = DB::table('professions')->select('id', 'title')->where('title', '=', 'Desarrollador back-end')->first();
        $professions = DB::table('professions')->where('title', '=', 'Desarrollador back-end')->first();
        $professions = DB::table('professions')->where('title', 'Desarrollador back-end')->first();
        $professions = DB::table('professions')->where(['title' => 'Desarrollador back-end'])->first();
        //Acomodados de diferente manera
        $professions = DB::table('professions')
            ->select('id', 'title')
            ->where('title', '=', 'Desarrollador back-end')
            ->first();
        //con value y cambiado profession id
        $professionId = DB::table('professions')
            ->select('id', 'title')
            ->where('title' , 'Desarrollador back-end')
            ->value('id');
        //Metodo magico
        $professionId = DB::table('professions')
            ->select('id', 'title')
            ->whereTitle('Desarrollador back-end')
            ->value('id');
        //dd($professions->first()); //$professions[0]
        //dd($professions->first()->id); //$professions[0]
        */
        $professionId = Profession::where('title', 'Desarrollador back-end')->value('id');
        User::create([
        'name' => 'Duilio Palacios',
            'email' => 'duilio@styde.net',
            'password' => bcrypt('laravel'),
            'profession_id' => $professionId,
        ]);
        factory(User::class)->create([
            'profession_id' => $professionId
        ]);
        factory(User::class)->create();
        factory(User::class, 48)->create();
    }
public function run ( ) { $ professionId = Profession :: where ( 'title' , 'Desarrollador back-end' ) -> value ( 'id' ) ; User :: create ( [ 'name' => 'Duilio Palacios' , 'email' => 'duilio@styde.net' , 'password' => bcrypt ( 'laravel' ) , 'profession_id' => $ professionId , ] ) ; factory ( User :: class ) -> create ( [ 'profession_id' => $ professionId ] ) ; factory ( User :: class ) -> create ( ) ; factory ( User :: class , 48 ) -> create ( ) ; }
Run the database seeds.
Run the database seeds .
//De forma manual //$professions = DB::select('SELECT id FROM professions WHERE title = ? LIMIT 0,1', ['Desarrollador back-end']); //para saber el indice y lo que trae //dd($professions); //dd('profession_id' => $professions[0]->id); /*con contructor laravel
        //$professions = DB::table('professions')->select('id')->take(1)->get();
        //para obtener un solo resultado y que no traiga la coleccion completa
        $professions = DB::table('professions')->select('id')->first();

        //Pasar mas argumentos
        $professions = DB::table('professions')->select('id', 'title')->where('title', '=', 'Desarrollador back-end')->first();
        $professions = DB::table('professions')->where('title', '=', 'Desarrollador back-end')->first();
        $professions = DB::table('professions')->where('title', 'Desarrollador back-end')->first();
        $professions = DB::table('professions')->where(['title' => 'Desarrollador back-end'])->first();
        //Acomodados de diferente manera
        $professions = DB::table('professions')
            ->select('id', 'title')
            ->where('title', '=', 'Desarrollador back-end')
            ->first();
        //con value y cambiado profession id
        $professionId = DB::table('professions')
            ->select('id', 'title')
            ->where('title' , 'Desarrollador back-end')
            ->value('id');

        //Metodo magico
        $professionId = DB::table('professions')
            ->select('id', 'title')
            ->whereTitle('Desarrollador back-end')
            ->value('id');
        //dd($professions);
        //dd($professions->first()); //$professions[0]
        //dd($professions->first()->id); //$professions[0]
        */ /*****Constructor de consultas***/ /*
         * DB::table('users')->insert([
            'name' => 'Duilio Palacios',
            'email' => 'duilio@styde.net',
            //bcrypt encrypta la contraseña
            'password' => bcrypt('laravel'),
            //'profession_id' => $professions[0]->id,
            //'profession_id' => $professions->first()->id,
            //'profession_id' => $professions->id,
            'profession_id' => $professionId,
        ]);
        */ /***Eloquent***/ //bcrypt encrypta la contraseña //'profession_id' => $professions[0]->id, //'profession_id' => $professions->first()->id, //'profession_id' => $professions->id, //Crear usuarios de forma aleatorea //agregar 48 usuarios