Agregado rol de ollas y usuarios para cada barrio
This commit is contained in:
parent
4bbab3a8f9
commit
8b86cddb33
1 changed files with 40 additions and 0 deletions
40
database/migrations/2025_06_20_040800_user_role_ollas.php
Normal file
40
database/migrations/2025_06_20_040800_user_role_ollas.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\GrupoDeCompra;
|
||||||
|
use App\User;
|
||||||
|
use App\UserRole;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
|
class UserRoleOllas extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$ollasRol = UserRole::firstOrCreate(['nombre' => 'ollas']);
|
||||||
|
$barrios = GrupoDeCompra::all();
|
||||||
|
foreach ($barrios as $barrio) {
|
||||||
|
$barrio->users()->firstOrCreate([
|
||||||
|
'name' => $barrio->nombre . '_ollas',
|
||||||
|
'password' => Hash::make('123'),
|
||||||
|
'role_id' => $ollasRol->id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
$ollasRol = UserRole::where('nombre', 'ollas')->firstOrFail();
|
||||||
|
User::where('role_id', $ollasRol->id)->delete();
|
||||||
|
$ollasRol->delete();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue