protected static function boot() { parent::boot(); Contact::creating(function ($contact) { $contact->company_id = $contact->company_id ?: Auth::user()['company_id']; }); }
public function search(Request $request) { $search = $request->search; $contacts = []; if (!empty($search)) { $contacts = Contact::where('name', 'like', "%{$search}%")->orWhere('nickname', 'like', "%{$search}%")->get(); } return view('agenda', compact('contacts')); }
public function getInitials() { $initials = []; foreach (Contact::all() as $contact) { $initials[] = strtoupper(substr($contact->nickname, 0, 1)); } sort($initials); return array_unique($initials); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('contacts')->delete(); Contact::forceCreate(['company_id' => 1, 'contact_type_id' => 3, 'name' => 'Administrator', 'country' => 'Country', 'city' => 'City']); $company = Company::find(1); $company->contact_id = 1; $company->save(); Contact::forceCreate(['company_id' => 1, 'contact_type_id' => 5, 'name' => 'Vendor Name']); Contact::forceCreate(['company_id' => 1, 'contact_type_id' => 4, 'name' => 'Driver Name', 'license_no' => 'license']); }
public function createContact($name, $company_id) { $typeDetail = Type::where('entity_key', 'contact')->where(function ($query) { $query->where('name', Lang::get('setup.detail'))->orWhere('name', 'detail'); })->where('company_id', $company_id)->first(); $contactUser = Contact::forceCreate(['company_id' => $company_id, 'contact_type_id' => $typeDetail->id, 'name' => $name]); $contactUser->save(); $this->contact_id = $contactUser->id; $this->save(); return $contactUser; }
public static function getContacts($type = null, $optionalChoice = false) { $contacts = Contact::where('contacts.company_id', Auth::user()['company_id']); if (!empty($type)) { $contacts = $contacts->join('types', 'contacts.contact_type_id', '=', 'types.id')->where('types.name', $type); } $contacts = $contacts->lists('contacts.name', 'contacts.id'); if ($optionalChoice) { $contacts->prepend("", ""); } return $contacts; }
public function testAccessDeniedCompany() { $user = factory(\App\Entities\User::class)->create(); $user->setUp(); $this->actingAs($user); $this->visit('/contact/1/edit'); $this->see(Lang::get('general.accessdenied')); $contact = Contact::find(1); $contact->companies()->delete(); $contact->entries()->delete(); $contact->models()->delete(); $contact->tripsDriver()->delete(); $contact->tripsVendor()->delete(); $contact->users()->delete(); $this->visit('/contact/destroy/1'); $this->see(Lang::get('general.accessdenied')); }
public function testDelete() { $idDelete = Contact::all()->last()['id']; factory(\App\Entities\Company::class)->create(['contact_id' => $idDelete]); $this->seeInDatabase('contacts', ['id' => $idDelete]); $this->visit('/contact/destroy/' . $idDelete)->seePageIs('/contact')->see('Este registro possui refer'); $this->seeIsNotSoftDeletedInDatabase('contacts', ['id' => $idDelete]); $contact = Contact::find($idDelete); $contact->companies()->delete(); $contact->entries()->delete(); $contact->models()->delete(); $contact->tripsDriver()->delete(); $contact->tripsVendor()->delete(); $contact->users()->delete(); $this->seeInDatabase('contacts', ['id' => $idDelete]); $this->visit('/contact/destroy/' . $idDelete); $this->seeIsSoftDeletedInDatabase('contacts', ['id' => $idDelete]); }
public function destroy($id) { Contact::find($id)->delete(); return redirect()->route('agenda.index'); }
public function create($contactId) { $contact = Contact::find($contactId); return view('phones.create', compact('contact')); }
public function show($idVehicle, $dateIni = null, $dateEnd = null) { $vehicle = $this->vehicleRepo->find($idVehicle); $this->helper->validateRecord($vehicle); $fleetData = $this->fleetRepo->getFleetData($vehicle->id); $localizationData = $this->vehicleRepo->getLocalizationData($idVehicle); $driverData = empty($localizationData->driver_id) ? "" : Contact::find($localizationData->driver_id); if (class_exists('Alientronics\\FleetanyWebReports\\Controllers\\ReportController')) { $objReportController = new ReportController($this->fleetRepo); $vehicleHistory = $objReportController->vehicleHistory($fleetData, $dateIni, $dateEnd); $tireSensorData = $vehicleHistory['tireSensorData']; $dateIni = $vehicleHistory['dateIni']; $timeIni = $vehicleHistory['timeIni']; $timeEnd = $vehicleHistory['timeEnd']; } else { $tireSensorData = []; $dateIni = ""; $timeIni = ""; $timeEnd = ""; } return view("vehicle.show", compact('vehicle', 'fleetData', 'localizationData', 'driverData', 'tireSensorData', 'dateIni', 'timeIni', 'timeEnd')); }
public function destroy($id) { $this->contact->find($id)->delete(); return redirect()->route('contacts.index'); }