38 lines
		
	
	
	
		
			846 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
	
		
			846 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| use App\Producto;
 | |
| use Illuminate\Database\Migrations\Migration;
 | |
| use Illuminate\Database\Schema\Blueprint;
 | |
| use Illuminate\Support\Facades\Schema;
 | |
| 
 | |
| class AgregarEsSolidario extends Migration
 | |
| {
 | |
|     /**
 | |
|      * Run the migrations.
 | |
|      *
 | |
|      * @return void
 | |
|      */
 | |
|     public function up()
 | |
|     {
 | |
|         Schema::table('productos', function (Blueprint $table) {
 | |
|             $table->boolean('es_solidario')->default(false);
 | |
|         });
 | |
| 
 | |
|         foreach (Producto::all() as $producto) {
 | |
|             $producto->es_solidario = $producto->proveedor_id != null;
 | |
|             $producto->save();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Reverse the migrations.
 | |
|      *
 | |
|      * @return void
 | |
|      */
 | |
|     public function down()
 | |
|     {
 | |
|         Schema::table('productos', function (Blueprint $table) {
 | |
|             $table->dropColumn('es_solidario');
 | |
|         });
 | |
|     }
 | |
| }
 |