Agregado modelo, tabla, y columna en subpedidos para tipo pedido
This commit is contained in:
parent
78b9d682cc
commit
441007e66b
3 changed files with 58 additions and 1 deletions
|
@ -12,7 +12,7 @@ use App\Filtros\FiltroDeSubpedido;
|
|||
|
||||
class Subpedido extends Model
|
||||
{
|
||||
protected $fillable = ['grupo_de_compra_id', 'aprobado', 'nombre', 'devoluciones_total', 'devoluciones_notas'];
|
||||
protected $fillable = ['grupo_de_compra_id', 'aprobado', 'nombre', 'devoluciones_total', 'devoluciones_notas', 'tipo_pedido_id'];
|
||||
|
||||
public function productos(): BelongsToMany
|
||||
{
|
||||
|
@ -24,6 +24,11 @@ class Subpedido extends Model
|
|||
return $this->belongsTo(GrupoDeCompra::class);
|
||||
}
|
||||
|
||||
public function tipoPedido(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(TipoPedido::class);
|
||||
}
|
||||
|
||||
// Permite que se apliquen los filtros al hacer una request (por ejemplo, de búsqueda)
|
||||
public function scopeFiltrar($query, FiltroDeSubpedido $filtros): Builder
|
||||
{
|
||||
|
|
10
app/TipoPedido.php
Normal file
10
app/TipoPedido.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TipoPedido extends Model
|
||||
{
|
||||
protected $fillable = ["nombre"];
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
use App\TipoPedido;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateTipoPedidosTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('tipo_pedidos', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string("nombre");
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
$hogar = TipoPedido::firstOrCreate(['nombre' => 'hogar']);
|
||||
|
||||
Schema::table('subpedidos', function (Blueprint $table) use ($hogar) {
|
||||
$table->foreignId('tipo_pedido_id')->default($hogar->id);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('tipo_pedidos');
|
||||
Schema::table('subpedidos', function (Blueprint $table) {
|
||||
$table->dropColumn('tipo_pedido_id');
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue