/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('models')->delete();
     Model::forceCreate(['model_type_id' => 2, 'vendor_id' => 2, 'name' => 'Generic Car', 'company_id' => 1]);
     Model::forceCreate(['model_type_id' => 10, 'vendor_id' => 2, 'name' => 'Generic Tire', 'company_id' => 1]);
     Model::forceCreate(['model_type_id' => 11, 'vendor_id' => 2, 'name' => 'Generic Sensor', 'company_id' => 1]);
 }
Beispiel #2
0
 public static function boot()
 {
     parent::boot();
     Model::creating(function ($model) {
         $model->company_id = $model->company_id ?: Auth::user()['company_id'];
     });
 }
 public static function getModels($entity_key = null, $idType = null)
 {
     $models = Model::join('types', 'models.model_type_id', '=', 'types.id')->where('models.company_id', Auth::user()['company_id']);
     if (!empty($entity_key)) {
         $models = $models->where('types.entity_key', $entity_key);
     }
     if (!empty($idType)) {
         $models = $models->where('types.id', $idType);
     }
     $models = $models->lists('models.name', 'models.id');
     return $models;
 }
 public function testAccessDeniedCompany()
 {
     $user = factory(\App\Entities\User::class)->create();
     $user->setUp();
     $this->actingAs($user);
     $this->visit('/model/1/edit');
     $this->see(Lang::get('general.accessdenied'));
     $model = Model::find(1);
     $model->vehicles()->delete();
     $this->visit('/model/destroy/1');
     $this->see(Lang::get('general.accessdenied'));
 }
 public function testDelete()
 {
     $idDelete = Model::all()->last()['id'];
     factory(\App\Entities\Vehicle::class)->create(['model_vehicle_id' => $idDelete]);
     $this->seeInDatabase('models', ['id' => $idDelete]);
     $this->visit('/model/destroy/' . $idDelete)->seePageIs('/model')->see('Este registro possui refer');
     $this->seeIsNotSoftDeletedInDatabase('models', ['id' => $idDelete]);
     $model = Model::find($idDelete);
     $model->vehicles()->delete();
     $this->seeInDatabase('models', ['id' => $idDelete]);
     $this->visit('/model/destroy/' . $idDelete);
     $this->seeIsSoftDeletedInDatabase('models', ['id' => $idDelete]);
 }
Beispiel #6
0
 public function setUp($lang = null)
 {
     $company = Company::forceCreate(['name' => $this->name . ' Inc.']);
     $company->save();
     $this->setUserProperties($company, $lang);
     $this->createGenericTypes($company);
     $typeTire = Type::forceCreate(['entity_key' => 'part', 'name' => Lang::get('setup.tire'), 'company_id' => $company->id]);
     $typeSensor = Type::forceCreate(['entity_key' => 'part', 'name' => Lang::get('setup.sensor'), 'company_id' => $company->id]);
     $typeCar = Type::forceCreate(['entity_key' => 'vehicle', 'name' => Lang::get('setup.car'), 'company_id' => $company->id]);
     $typeTruck = Type::forceCreate(['entity_key' => 'vehicle', 'name' => Lang::get('setup.truck'), 'company_id' => $company->id]);
     $typeVendor = Type::forceCreate(['entity_key' => 'contact', 'name' => Lang::get('setup.vendor'), 'company_id' => $company->id]);
     $typeDriver = Type::forceCreate(['entity_key' => 'contact', 'name' => Lang::get('setup.driver'), 'company_id' => $company->id]);
     $contactDetail = $this->createContact($this->name, $company->id);
     $company->contact_id = $contactDetail->id;
     $company->save();
     $contactVendor = Contact::forceCreate(['company_id' => $company->id, 'contact_type_id' => $typeVendor->id, 'name' => Lang::get('setup.GenericVendor'), 'license_no' => '123456']);
     Contact::forceCreate(['company_id' => $company->id, 'contact_type_id' => $typeDriver->id, 'name' => Lang::get('setup.GenericDriver'), 'license_no' => '123456']);
     $modelCar = Model::forceCreate(['model_type_id' => $typeCar->id, 'vendor_id' => $contactVendor->id, 'name' => Lang::get('setup.GenericCar'), 'company_id' => $company->id]);
     Model::forceCreate(['model_type_id' => $typeTruck->id, 'vendor_id' => $contactVendor->id, 'name' => Lang::get('setup.GenericTruck'), 'company_id' => $company->id]);
     Model::forceCreate(['model_type_id' => $typeTire->id, 'name' => Lang::get('setup.GenericTire'), 'company_id' => $company->id]);
     $modelSensor = Model::forceCreate(['model_type_id' => $typeSensor->id, 'name' => Lang::get('setup.GenericSensor'), 'company_id' => $company->id]);
     $vehicle = Vehicle::forceCreate(['model_vehicle_id' => $modelCar->id, 'number' => Lang::get('setup.VehiclePlate'), 'initial_miliage' => 123, 'actual_miliage' => 123, 'cost' => 50000, 'description' => Lang::get('setup.GenericVehicle'), 'company_id' => $company->id]);
     Part::forceCreate(['vehicle_id' => $vehicle->id, 'vendor_id' => $contactVendor->id, 'part_type_id' => $typeSensor->id, 'part_model_id' => $modelSensor->id, 'cost' => 1, 'name' => Lang::get('setup.GenericSensor'), 'number' => '0000000001', 'miliage' => 1, 'position' => 1, 'lifecycle' => 1, 'company_id' => $company->id]);
 }