Company check implemented in customer document module

This commit is contained in:
Prashant Singh 2019-06-29 15:21:53 +05:30
parent d164178609
commit 6c003f949f
5 changed files with 40 additions and 2 deletions

View File

@ -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();
});
}

View File

@ -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));
}
}
}

View File

@ -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;
}
}
}

View File

@ -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);

View File

@ -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));
}
}
}