Company check implemented in customer document module
This commit is contained in:
parent
d164178609
commit
6c003f949f
|
|
@ -21,6 +21,8 @@ class CustomerDocumentsTable extends Migration
|
|||
$table->string('type');
|
||||
$table->string('path');
|
||||
$table->integer('customer_id')->default(0);
|
||||
$table->integer('company_id')->unsigned();
|
||||
$table->foreign('company_id')->references('id')->on('customer_documents')->onDelete('cascade');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,5 +9,22 @@ class CustomerDocument extends Model implements CustomerDocumentContract
|
|||
{
|
||||
protected $table = 'customer_documents';
|
||||
|
||||
protected $fillable = ['name', 'path', 'customer_id', 'description', 'type', 'status'];
|
||||
protected $fillable = ['name', 'path', 'customer_id', 'description', 'type', 'status', 'company_id'];
|
||||
|
||||
/**
|
||||
* Create a new Eloquent query builder for the model.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
public function newEloquentBuilder($query)
|
||||
{
|
||||
$company = Company::getCurrent();
|
||||
|
||||
if (auth()->guard('super-admin')->check() || ! isset($company->id)) {
|
||||
return new \Illuminate\Database\Eloquent\Builder($query);
|
||||
} else {
|
||||
return new \Illuminate\Database\Eloquent\Builder($query->where('customer_documents' . '.company_id', $company->id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\CustomerDocument\Observers\Attribute;
|
||||
|
||||
use Webkul\CustomerDocument\Models\CustomerDocument;
|
||||
|
||||
use Company;
|
||||
|
||||
class CustomerDocumentObserver
|
||||
{
|
||||
public function creating(CustomerDocument $model)
|
||||
{
|
||||
if (! auth()->guard('super-admin')->check()) {
|
||||
$model->company_id = Company::getCurrent()->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,8 @@ class CustomerDocumentServiceProvider extends ServiceProvider
|
|||
|
||||
$this->loadMigrationsFrom(__DIR__ . '/../Database/migrations');
|
||||
|
||||
\Webkul\CustomerDocument\Models\CustomerDocument::observe(\Webkul\CustomerDocument\Observers\CustomerDocument::class);
|
||||
|
||||
$this->app->register(ModuleServiceProvider::class);
|
||||
|
||||
$this->app->register(EventServiceProvider::class);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class Category extends BaseModel
|
|||
if (auth()->guard('super-admin')->check() || ! isset($company->id)) {
|
||||
return new QueryBuilder($query);
|
||||
} else {
|
||||
return new QueryBuilder($query->where('company_id', $company->id));
|
||||
return new QueryBuilder($query->where('categories.company_id', $company->id));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue