first commit
This commit is contained in:
37
app/Models/Document.php
Normal file
37
app/Models/Document.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Document extends Model
|
||||
{
|
||||
protected $table = 'document';
|
||||
|
||||
use HasFactory;
|
||||
|
||||
const STATUS_NOT_APPLIED = 0;
|
||||
const STATUS_APPLIED = 1;
|
||||
const TYPE_TO = 0;
|
||||
const TYPE_FROM = 1;
|
||||
protected $fillable = ['type', 'date', 'status'];
|
||||
|
||||
public function products(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Product::class);
|
||||
}
|
||||
|
||||
public static function getTitlesOfTypes()
|
||||
{
|
||||
return [self::TYPE_TO => 'Поступление', self::TYPE_FROM => 'Расход'];
|
||||
}
|
||||
|
||||
public function documentProducts(): HasMany
|
||||
{
|
||||
return $this->hasMany(DocumentProduct::class);
|
||||
}
|
||||
|
||||
}
|
24
app/Models/DocumentProduct.php
Normal file
24
app/Models/DocumentProduct.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class DocumentProduct extends Model
|
||||
{
|
||||
protected $table = 'document_product';
|
||||
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['product_id', 'document_id', 'quantity', 'past_quantity'];
|
||||
|
||||
public function product(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
}
|
22
app/Models/Product.php
Normal file
22
app/Models/Product.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Product extends Model
|
||||
{
|
||||
protected $table = 'product';
|
||||
|
||||
use HasFactory; use SoftDeletes;
|
||||
|
||||
protected $fillable = ['name', 'article', 'price', 'quantity'];
|
||||
|
||||
public function documents(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Document::class);
|
||||
}
|
||||
}
|
45
app/Models/User.php
Executable file
45
app/Models/User.php
Executable file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
Reference in New Issue
Block a user