Initial Commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Brand extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
];
|
||||
|
||||
public function models()
|
||||
{
|
||||
return $this->hasMany(ProductModel::class,'brand_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->hasMany(Product::class,'brand_id','id')->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Building extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public function rooms()
|
||||
{
|
||||
return $this->hasMany(Room::class,'building_id','id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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\SoftDeletes;
|
||||
|
||||
class Cabel extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CabelCategory::class,'cabel_category_id')->withTrashed();
|
||||
}
|
||||
|
||||
public function loans()
|
||||
{
|
||||
return $this->morphtoMany(User::class, 'loanable','loans')->where('loan_type_id','=',LoanType::where('name','=','Loan')->first()->id)->withTrashed();
|
||||
}
|
||||
|
||||
public function reservations()
|
||||
{
|
||||
return $this->morphtoMany(User::class, 'loanable','loans')->where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id)->withTrashed();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class CabelCategory extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public function cabels()
|
||||
{
|
||||
return $this->hasMany(Cabel::class,'cabel_category_id','id')->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Contract extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'timestamp',
|
||||
'user_id',
|
||||
'type'
|
||||
];
|
||||
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id')->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Loan extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'room_id',
|
||||
'loan_type_id',
|
||||
'loanable_id',
|
||||
'loanable_type',
|
||||
'date_start',
|
||||
'date_end',
|
||||
'date_deadline',
|
||||
];
|
||||
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id')->withTrashed();
|
||||
}
|
||||
|
||||
public function room()
|
||||
{
|
||||
return $this->belongsTo(Room::class, 'room_id')->withTrashed();
|
||||
}
|
||||
|
||||
public function type()
|
||||
{
|
||||
return $this->belongsTo(LoanType::class, 'loan_type_id');
|
||||
}
|
||||
|
||||
public function loanable()
|
||||
{
|
||||
return $this->morphTo()->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class LoanType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = "loan_types";
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class LoanerType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Log extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'target_id',
|
||||
'loggable_type',
|
||||
'loggable_id',
|
||||
'log',
|
||||
'amount'
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id')->withTrashed();
|
||||
}
|
||||
|
||||
public function target()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'target_id')->withTrashed();
|
||||
}
|
||||
|
||||
public function action()
|
||||
{
|
||||
return $this->belongsTo(LogAction::class, 'log_action_id');
|
||||
}
|
||||
|
||||
public function loggable()
|
||||
{
|
||||
return $this->morphTo()->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class LogAction extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Note extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'note_type_id',
|
||||
'user_id',
|
||||
'note',
|
||||
'loanable_type',
|
||||
'loanable_id'
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class,'user_id')->withTrashed();
|
||||
}
|
||||
|
||||
public function type()
|
||||
{
|
||||
return $this->belongsTo(NoteType::class,'note_type_id');
|
||||
}
|
||||
|
||||
public function loanable()
|
||||
{
|
||||
return $this->morphTo()->withTrashed();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class NoteType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Permission extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name'
|
||||
];
|
||||
|
||||
/**
|
||||
* Gets all the Roles with a relation with the Permission(Many to Many through role_has_permission)
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function roles(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Role::class, "role_has_permission", "permission_id", "role_id")->withTimestamps();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Product extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(ProductCategory::class,'product_category_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function subcategory()
|
||||
{
|
||||
return $this->belongsTo(ProductSubcategory::class,'product_subcategory_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function brand()
|
||||
{
|
||||
return $this->belongsTo(Brand::class,'brand_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function model()
|
||||
{
|
||||
return $this->belongsTo(ProductModel::class,'product_model_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function loans()
|
||||
{
|
||||
return $this->morphtoMany(User::class, 'loanable','loans')->where('loan_type_id','=',LoanType::where('name','=','Loan')->first()->id);
|
||||
}
|
||||
|
||||
public function reservations()
|
||||
{
|
||||
return $this->morphtoMany(User::class, 'loanable','loans')->where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class ProductCategory extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
];
|
||||
|
||||
public function subcategories()
|
||||
{
|
||||
return $this->hasMany(ProductSubcategory::class,'product_category_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->hasMany(Product::class,'product_category_id','id')->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class ProductModel extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'brand_id'
|
||||
];
|
||||
|
||||
public function brand()
|
||||
{
|
||||
return $this->belongsTo(Brand::class,'brand_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->hasMany(Product::class,'product_model_id','id')->withTrashed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class ProductSubcategory extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'product_category_id'
|
||||
];
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(ProductCategory::class,'product_category_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->hasMany(Product::class,'product_subcategory_id','id')->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Role extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'name'
|
||||
];
|
||||
|
||||
/**
|
||||
* Gets all the Permissions with a relation with the roles(Many to Many through role_has_permission)
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function permissions(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Permission::class, "role_has_permission", 'role_id', 'permission_id')->withTimestamps();
|
||||
}
|
||||
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(User::class,'role_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Room extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public function building()
|
||||
{
|
||||
return $this->belongsTo(Building::class,'building_id','id')->withTrashed()
|
||||
;
|
||||
}
|
||||
|
||||
public function reservations()
|
||||
{
|
||||
return $this->hasMany(Loan::class,'room_id')
|
||||
->where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id)
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\users\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use LdapRecord\Laravel\Auth\LdapAuthenticatable;
|
||||
use LdapRecord\Laravel\Auth\AuthenticatesWithLdap;
|
||||
|
||||
class User extends Authenticatable implements LdapAuthenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable, SoftDeletes, AuthenticatesWithLdap;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'username',
|
||||
'password',
|
||||
'guid',
|
||||
'domain'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Gets the Loaner Type that the users belongs to
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function loanerType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(LoanerType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the roles that the users belongs to
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function role(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Role::class);
|
||||
}
|
||||
|
||||
public function loans()
|
||||
{
|
||||
return $this->hasMany(Loan::class,'user_id')
|
||||
->where('loan_type_id','=',LoanType::where('name','=','Loan')->first()->id)
|
||||
;
|
||||
}
|
||||
|
||||
public function reservations()
|
||||
{
|
||||
return $this->hasMany(Loan::class,'user_id')
|
||||
->where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id)
|
||||
;
|
||||
}
|
||||
|
||||
public function notes()
|
||||
{
|
||||
return $this->hasMany(Note::class,'user_id');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user