Esempio n. 1
0
 public function addSublease(Request $request)
 {
     $input = $request->all();
     $tenant = Tenant::find($input['tenant_id']);
     $lease = Lease::find($input['lease_id']);
     // lease->tenants()->where('tenant_id',$tenant->id)->sync([$tenant->id => ['sublessor_name' => $input['sublessor_name']]]);
     $lease_tenant = $lease->tenants()->where('tenant_id', $tenant->id)->first();
     $lease_tenant->pivot->sublessor_name = $input['sublessor_name'];
     $lease_tenant->pivot->save();
     return redirect()->route('apartments.lease.show', ['name' => $lease->apartment->name, 'id' => $lease->id]);
 }
Esempio n. 2
0
 public function choose(Apartment $apartment, Lease $lease, Request $request)
 {
     $leasemonth = Carbon::parse($request->input('leasemonth'));
     $input = $request->all();
     $tenant = Tenant::with('payments')->find($input['tenant_id']);
     //$payments = $lease->payments()->where('tenant_id',$input['tenant_id']->get());
     return view('payments.choose', ['title' => $lease->apartment->name . ' Lease: ' . $lease->startdate->format('n/j/Y') . ' - ' . $lease->enddate->format('n/j/Y'), 'lease' => $lease, 'tenant' => $tenant, 'leasemonth' => $leasemonth]);
 }
 /**
  * Register a new tenant.
  *
  * @throws \Stryve\Exceptions\InvalidSubdomainException;
  * @throws \Stryve\Exceptions\TenantAlreadyExistsException;
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response (HTTP 201 Created)
  */
 public function store(Request $request)
 {
     // \DB::connection('svr1');
     // \Config::get
     // dd(\DB::connection('svr2'));
     // sanitize passed params and get geo data
     $request = $this->tenant->sanitizeAndExpandRegistrationRequest($request);
     $subdomain = $request->subdomain;
     $database = $request->database;
     $database_prefix = $request->database_prefix;
     // check subdomain meets length and regex specifications
     if (!$this->tenant->isValidSubdomain($subdomain)) {
         throw new InvalidSubdomainException();
     }
     // check subdomain is not already taken
     if ($this->tenant->exists($subdomain)) {
         throw new TenantAlreadyExistsException();
     }
     // check subdomain is not reserved
     if ($this->reserved_subdomain->isReserved($subdomain)) {
         throw new TenantAlreadyExistsException();
     }
     // set the connection options
     $options = ['database' => $database, 'prefix' => $database_prefix];
     // get the default connection detail so we can revert back
     $defaultConnection = getDefaultDatabaseConnetion();
     // set the new connection
     setDatabaseConnetion($database, $options);
     // create the new tenants database
     $this->tenant->createNewTenantDatabase($database);
     // run the new tenant migration
     $this->tenant->runNewTenantMigration($database);
     // \DB::disconnect($request->database);
     // dd(\DB::connection('svr1'));
     // run new tenant seeder
     $this->tenant->runNewTenantTableSeeder($database);
     // reset the default database connection
     // setDatabaseConnetion($defaultConnection['connection'], $defaultConnection['options']);
     // $default = \Config::get('database.default');
     // dd(\Config::get('database.connections.' . $default));
     exit('done');
     // \DB::statement(\DB::raw('CREATE DATABASE ' . $request->database));
     // \Artisan::call('migrate', [
     //     '--database' => $request->database,
     //     '--path' => 'app/Stryve/Database/Migrations/Tenant'
     // ]);
     //
     /***/
     // // Will contain the array of connections that appear in our database config file.
     // $connections = \Config::get('database.connections');
     // // This line pulls out the default connection by key (by default it's `mysql`)
     // $defaultConnection = $connections[\Config::get('database.default')];
     // // Now we simply copy the default connection information to our new connection.
     // $newConnection = $defaultConnection;
     // $options = [
     //     'database'  => $request->database,
     //     'prefix'    => $request->database_prefix
     // ];
     // // Override the database name.
     // foreach($newConnection as $item => $value)
     //     $newConnection[$item] = isset($options[$item]) ? $options[$item] : $newConnection[$item];
     // // dd($newConnection);
     // // $newConnection['database'] = $request->database;
     // // This will add our new connection to the run-time configuration for the duration of the request.
     // \Config::set('database.connections.'.$request->database, $newConnection);
     /***/
     // count number of table from each database server
     // select database server with the least number of databases
     // // set the default connections options so we can revert back
     // $conn_name = \Config::get('database.default');
     // $defaultOptions = \Config::get('database.connections.'.$conn_name);
     // // clone the default options
     // $default = $defaultOptions;
     // // the new conneciton options
     // $options = [
     //     'database'  => $request->database,
     //     'prefix'    => $request->database_prefix
     // ];
     // // replace default options
     // foreach($default as $item => $value)
     //     $default[$item] = isset($options[$item]) ? $options[$item] : $default[$item];
     // // set the new connection
     // \Config::set('database.connections.'.$conn_name, $default);
     // try inserting new tenant DB
     \DB::statement(\DB::raw('CREATE DATABASE ' . $request->database));
     // dd(\Config::get('database.connections.db_svr_0'));
     // $this->tenant->runNewTenantMigration($request->database);
     // run new tenant migration
     \Artisan::call('migrate', ['--database' => $conn->getConnectionName(), '--path' => 'app/Stryve/Database/Migrations/Tenant']);
     // \Config::set('database.connections.'.\Config::get('database.default'), $defaultConnection);
     // dd(\Config::get('database.connections.'.\Config::get('database.default')));
     exit('done');
     // set the connection to insert the new tenant database
     // $connection = new ConnectOTF($options); // $this->tenant->setNewDbConnection($request);
     // dd($connection->getDefaultOptions());
     // create new tenant database
     // $connection->createDatabase($request->database);
     // dd(\Config::get('database.connections.'.$connection->getConnectionName()));
     // perform initaial database table migration
     // perform initial database seed
     // reset the connection bac to its default
     // $connection->getConnection()->resetDefaultConnection();
     // add request data to stryve_admin database
     // \Artisan::call('migrate:rollback');
 }
Esempio n. 4
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show(Apartment $apartment, Lease $lease)
 {
     //
     $title = $lease->apartment->property->name . ' ' . $lease->apartment->name . ' Lease: ' . $lease->startdate->format('n/j/Y') . ' - ' . $lease->enddate->format('n/j/Y');
     $tenants = Tenant::all();
     return view('leases.show', ['title' => $title, 'lease' => $lease, 'tenants' => $tenants]);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, contractRequest $request)
 {
     // use my custom handler to fix dates, check if dates are valid and see if the stores are available to rent
     $contractFormHandler = new ContractFormHandler($request);
     if ($contractFormHandler->hasErrors) {
         \Session::flash('message', $contractFormHandler->errorMessages);
         \Session::flash('messageType', 'warning');
         return redirect()->route('contracts.edit', ['contracts' => $id])->withInput();
     }
     // remove previous associations to replace with new form
     $contract = Contract::findOrFail($id);
     $contract->tenant()->dissociate();
     $contract->properties()->detach();
     // update info
     $contract->description = $request->description;
     $contract->effective_date = $request->effective_date;
     $contract->expiry_date = $request->expiry_date;
     $contract->terms = $request->terms;
     $contract->signing_date = $request->signing_date;
     $contract->amount = $request->amount;
     $contract->currency = $request->currency;
     // associate with tenant
     $tenant = Tenant::findOrFail($request->tenant);
     $contract->tenant()->associate($tenant);
     // attach properties
     foreach ($request->properties as $key => $property) {
         $propertyInFocus = Property::findOrFail($property);
         $contract->properties()->attach($propertyInFocus);
     }
     $contract->save();
     return redirect()->route('contracts.index');
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //
     return Tenant::all();
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Request $request)
 {
     Tenant::destroy($request->id);
     return Redirect::route('tenants.index');
 }