this makes possible adding extra attributes to models

This commit is contained in:
Sevan Nerse 2021-02-26 17:16:48 +03:00
parent 962e626c9e
commit 5878c96c3a
16 changed files with 54 additions and 99 deletions

View File

@ -21,10 +21,23 @@ abstract class Model extends Eloquent
'enabled' => 'boolean',
];
public $extras = [
public $allAttributes = [
//
];
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
* @return void
*/
public function __construct(array $attributes = [])
{
$this->allAttributes = $attributes;
parent::__construct($attributes);
}
public static function observe($classes)
{
parent::observe($classes);

View File

@ -1,24 +0,0 @@
<?php
namespace App\Events\Common;
use App\Abstracts\Event;
class ModelCreated extends Event
{
public $model;
public $attributes;
/**
* Create a new event instance.
*
* @param $model
* @param $attributes
*/
public function __construct($model, $attributes)
{
$this->model = $model;
$this->attributes = $attributes;
}
}

View File

@ -3,7 +3,6 @@
namespace App\Imports\Banking;
use App\Abstracts\Import;
use App\Events\Common\ModelCreated;
use App\Http\Requests\Banking\Transaction as Request;
use App\Models\Banking\Transaction as Model;
@ -11,11 +10,7 @@ class Transactions extends Import
{
public function model(array $row)
{
$model = new Model($row);
event(new ModelCreated($model, $row));
return $model;
return new Model($row);
}
public function map($row): array

View File

@ -3,7 +3,6 @@
namespace App\Imports\Banking;
use App\Abstracts\Import;
use App\Events\Common\ModelCreated;
use App\Models\Banking\Transaction;
use App\Models\Banking\Transfer as Model;
use App\Models\Setting\Category;
@ -16,11 +15,7 @@ class Transfers extends Import
public function model(array $row)
{
$model = new Model($row);
event(new ModelCreated($model, $row));
return $model;
return new Model($row);
}
public function map($row): array

View File

@ -3,7 +3,6 @@
namespace App\Imports\Common\Sheets;
use App\Abstracts\Import;
use App\Events\Common\ModelCreated;
use App\Http\Requests\Common\Item as Request;
use App\Models\Common\Item as Model;
@ -11,11 +10,7 @@ class Items extends Import
{
public function model(array $row)
{
$model = new Model($row);
event(new ModelCreated($model, $row));
return $model;
return new Model($row);
}
public function map($row): array

View File

@ -3,7 +3,6 @@
namespace App\Imports\Purchases;
use App\Abstracts\Import;
use App\Events\Common\ModelCreated;
use App\Http\Requests\Banking\Transaction as Request;
use App\Models\Banking\Transaction as Model;
@ -11,11 +10,7 @@ class Payments extends Import
{
public function model(array $row)
{
$model = new Model($row);
event(new ModelCreated($model, $row));
return $model;
return new Model($row);
}
public function map($row): array

View File

@ -3,7 +3,6 @@
namespace App\Imports\Purchases\Sheets;
use App\Abstracts\Import;
use App\Events\Common\ModelCreated;
use App\Http\Requests\Document\DocumentItem as Request;
use App\Models\Document\Document;
use App\Models\Document\DocumentItem as Model;
@ -12,11 +11,7 @@ class BillItems extends Import
{
public function model(array $row)
{
$model = new Model($row);
event(new ModelCreated($model, $row));
return $model;
return new Model($row);
}
public function map($row): array

View File

@ -3,7 +3,6 @@
namespace App\Imports\Purchases\Sheets;
use App\Abstracts\Import;
use App\Events\Common\ModelCreated;
use App\Http\Requests\Document\Document as Request;
use App\Models\Document\Document as Model;
use Illuminate\Support\Str;
@ -12,11 +11,7 @@ class Bills extends Import
{
public function model(array $row)
{
$model = new Model($row);
event(new ModelCreated($model, $row));
return $model;
return new Model($row);
}
public function map($row): array

View File

@ -3,7 +3,6 @@
namespace App\Imports\Purchases;
use App\Abstracts\Import;
use App\Events\Common\ModelCreated;
use App\Http\Requests\Common\Contact as Request;
use App\Models\Common\Contact as Model;
@ -11,11 +10,7 @@ class Vendors extends Import
{
public function model(array $row)
{
$model = new Model($row);
event(new ModelCreated($model, $row));
return $model;
return new Model($row);
}
public function map($row): array

View File

@ -3,7 +3,6 @@
namespace App\Imports\Sales;
use App\Abstracts\Import;
use App\Events\Common\ModelCreated;
use App\Http\Requests\Common\Contact as Request;
use App\Models\Common\Contact as Model;
@ -11,11 +10,7 @@ class Customers extends Import
{
public function model(array $row)
{
$model = new Model($row);
event(new ModelCreated($model, $row));
return $model;
return new Model($row);
}
public function map($row): array

View File

@ -3,7 +3,6 @@
namespace App\Imports\Sales;
use App\Abstracts\Import;
use App\Events\Common\ModelCreated;
use App\Http\Requests\Banking\Transaction as Request;
use App\Models\Banking\Transaction as Model;
@ -11,11 +10,7 @@ class Revenues extends Import
{
public function model(array $row)
{
$model = new Model($row);
event(new ModelCreated($model, $row));
return $model;
return new Model($row);
}
public function map($row): array

View File

@ -3,7 +3,6 @@
namespace App\Imports\Sales\Sheets;
use App\Abstracts\Import;
use App\Events\Common\ModelCreated;
use App\Http\Requests\Document\DocumentItem as Request;
use App\Models\Document\Document;
use App\Models\Document\DocumentItem as Model;
@ -12,11 +11,7 @@ class InvoiceItems extends Import
{
public function model(array $row)
{
$model = new Model($row);
event(new ModelCreated($model, $row));
return $model;
return new Model($row);
}
public function map($row): array

View File

@ -3,7 +3,6 @@
namespace App\Imports\Sales\Sheets;
use App\Abstracts\Import;
use App\Events\Common\ModelCreated;
use App\Http\Requests\Document\Document as Request;
use App\Models\Document\Document as Model;
use Illuminate\Support\Str;
@ -12,11 +11,7 @@ class Invoices extends Import
{
public function model(array $row)
{
$model = new Model($row);
event(new ModelCreated($model, $row));
return $model;
return new Model($row);
}
public function map($row): array

View File

@ -3,7 +3,6 @@
namespace App\Imports\Settings;
use App\Abstracts\Import;
use App\Events\Common\ModelCreated;
use App\Http\Requests\Setting\Category as Request;
use App\Models\Setting\Category as Model;
@ -11,11 +10,7 @@ class Categories extends Import
{
public function model(array $row)
{
$model = new Model($row);
event(new ModelCreated($model, $row));
return $model;
return new Model($row);
}
public function rules(): array

View File

@ -28,7 +28,7 @@ class Company extends Eloquent
'enabled' => 'boolean',
];
public $extras = [
public $allAttributes = [
//
];
@ -39,6 +39,19 @@ class Company extends Eloquent
*/
public $sortable = ['name', 'domain', 'email', 'enabled', 'created_at'];
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
* @return void
*/
public function __construct(array $attributes = [])
{
$this->allAttributes = $attributes;
parent::__construct($attributes);
}
public static function boot()
{
parent::boot();

View File

@ -20,12 +20,25 @@ class Setting extends Eloquent
*/
protected $fillable = ['company_id', 'key', 'value'];
public $extras = [
public $allAttributes = [
//
];
public $timestamps = false;
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
* @return void
*/
public function __construct(array $attributes = [])
{
$this->allAttributes = $attributes;
parent::__construct($attributes);
}
public function company()
{
return $this->belongsTo('App\Models\Common\Company');