diff --git a/app/Http/Middleware/Subpedido.php b/app/Http/Middleware/Subpedido.php index 3b64cdd..66e8051 100644 --- a/app/Http/Middleware/Subpedido.php +++ b/app/Http/Middleware/Subpedido.php @@ -15,7 +15,7 @@ class Subpedido */ public function handle($request, Closure $next) { - if (!session('subpedido')) { + if (!session('subpedido_nombre') || !session('subpedido_id')) { return redirect()->route('subpedidos.create'); } return $next($request); diff --git a/app/User.php b/app/User.php index e79dab7..9d9c786 100644 --- a/app/User.php +++ b/app/User.php @@ -36,4 +36,10 @@ class User extends Authenticatable protected $casts = [ 'email_verified_at' => 'datetime', ]; + + + public function grupoDeCompra() + { + return $this->belongsTo('App\GrupoDeCompra'); + } } diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index a4de1a4..30b7e0d 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -18,6 +18,7 @@ class CreateUsersTable extends Migration $table->string('name')->unique(); $table->string('email')->unique()->nullable(); $table->timestamp('email_verified_at')->nullable(); + $table->foreignId('grupo_de_compra_id')->nullable(); $table->string('password'); $table->rememberToken(); $table->timestamps(); diff --git a/database/seeds/GrupoDeCompraSeeder.php b/database/seeds/GrupoDeCompraSeeder.php index 2c16d48..c76a22d 100644 --- a/database/seeds/GrupoDeCompraSeeder.php +++ b/database/seeds/GrupoDeCompraSeeder.php @@ -20,7 +20,7 @@ class GrupoDeCompraSeeder extends Seeder $gdcToInsert = []; $usersToInsert = []; - foreach($registros as $registro){ + foreach($registros as $key => $registro){ $gdcToInsert[] = [ 'nombre' => $registro['barrio'], 'region' => $registro['region'], @@ -31,7 +31,8 @@ class GrupoDeCompraSeeder extends Seeder $usersToInsert[] = [ 'name' => $registro['barrio'], - 'password' => Hash::make($registro['barrio']) + 'password' => Hash::make($registro['barrio']), + 'grupo_de_compra_id' => $key ]; } diff --git a/public/js/app.js b/public/js/app.js index 731039a..6acdc50 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -7,7 +7,7 @@ Vue.component('nav-bar', { - +