imports arreglados y relaciones agregadas
This commit is contained in:
parent
382b973227
commit
a569a2a497
|
@ -2,7 +2,8 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Barrio extends Model
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Caracteristica extends Model
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Categoria extends Model
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Pedido extends Model
|
||||
|
@ -29,6 +30,22 @@ public function barrio(): BelongsTo
|
|||
*/
|
||||
public function productos(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Producto::class)->withPivot(['cantidad','total']);
|
||||
return $this->belongsToMany(Producto::class)->withPivot(['cantidad']);
|
||||
}
|
||||
|
||||
public function productosSinBonos() {
|
||||
return $this->productos()->where('bono',0)->all();
|
||||
}
|
||||
|
||||
function bonos() {
|
||||
return $this->productos()->where('bono',1)->all();
|
||||
}
|
||||
|
||||
function bonosDeTransporte() : int {
|
||||
$total = 0;
|
||||
foreach ($this->productosSinBonos() as $key => $producto) {
|
||||
$total += $producto->price * $producto->pivot->cantidad;
|
||||
}
|
||||
return 1 + ($total / 500);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Producto extends Model
|
||||
|
@ -29,7 +30,7 @@ public function categoria(): BelongsTo
|
|||
*/
|
||||
public function pedidos(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Pedido::class)->withPivot(['cantidad','total']);
|
||||
return $this->belongsToMany(Pedido::class)->withPivot(['cantidad']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Region extends Model
|
||||
|
|
Loading…
Reference in New Issue