├── .dockerignore ├── .env.example ├── .gitattributes ├── .github ├── dependabot.yml └── workflows │ └── laravel.yml ├── .gitignore ├── .mergify.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── Makefile ├── app ├── Console │ ├── Commands │ │ └── Inspire.php │ └── Kernel.php ├── Events │ └── Event.php ├── Exceptions │ └── Handler.php ├── Http │ ├── Controllers │ │ ├── Auth │ │ │ ├── AuthController.php │ │ │ └── PasswordController.php │ │ ├── Controller.php │ │ ├── ReservationController.php │ │ ├── SessionController.php │ │ ├── UserController.php │ │ └── VacationPropertyController.php │ ├── Kernel.php │ ├── Middleware │ │ ├── Authenticate.php │ │ ├── CheckForMaintenanceMode.php │ │ ├── EncryptCookies.php │ │ ├── RedirectIfAuthenticated.php │ │ ├── TrimStrings.php │ │ ├── TrustProxies.php │ │ └── VerifyCsrfToken.php │ └── Requests │ │ └── Request.php ├── Jobs │ └── Job.php ├── Listeners │ └── .gitkeep ├── Policies │ └── .gitkeep ├── Providers │ ├── AppServiceProvider.php │ ├── AuthServiceProvider.php │ ├── BroadcastServiceProvider.php │ ├── RouteServiceProvider.php │ └── TwilioRestClientProvider.php ├── Reservation.php ├── User.php └── VacationProperty.php ├── artisan ├── bootstrap ├── app.php ├── autoload.php └── cache │ └── .gitignore ├── composer.json ├── composer.lock ├── config ├── app.php ├── auth.php ├── broadcasting.php ├── cache.php ├── compile.php ├── database.php ├── filesystems.php ├── mail.php ├── queue.php ├── services.php ├── session.php └── view.php ├── database ├── .gitignore ├── factories │ └── ModelFactory.php ├── migrations │ ├── .gitkeep │ ├── 2014_10_12_000000_create_users_table.php │ ├── 2015_10_23_193814_create_vacation_properties_table.php │ └── 2015_10_23_194614_create_reservations_table.php └── seeds │ ├── .gitkeep │ ├── DatabaseSeeder.php │ └── ReservationSeeder.php ├── docker-compose.yml ├── gulpfile.js ├── package.json ├── phpspec.yml ├── phpunit.xml ├── public ├── .htaccess ├── css │ ├── application.css │ ├── main.css │ ├── scaffolds.css │ └── vacation_properties.css ├── favicon.ico ├── images │ ├── airtng-logo.png │ ├── spock.png │ └── tngbg.jpg ├── index.php └── robots.txt ├── readme.md ├── resources ├── assets │ └── sass │ │ └── app.scss ├── lang │ └── en │ │ ├── auth.php │ │ ├── pagination.php │ │ ├── passwords.php │ │ └── validation.php └── views │ ├── _messages.blade.php │ ├── errors │ └── 503.blade.php │ ├── home.blade.php │ ├── layouts │ └── master.blade.php │ ├── login.blade.php │ ├── newUser.blade.php │ ├── property │ ├── _propertyForm.blade.php │ ├── edit.blade.php │ ├── index.blade.php │ ├── newProperty.blade.php │ └── show.blade.php │ └── vendor │ └── .gitkeep ├── routes ├── api.php ├── channels.php ├── console.php └── web.php ├── server.php ├── storage ├── app │ └── .gitignore ├── framework │ ├── .gitignore │ ├── cache │ │ └── .gitignore │ ├── sessions │ │ └── .gitignore │ └── views │ │ └── .gitignore └── logs │ └── .gitignore ├── tests ├── ReservationControllerTest.php ├── TestCase.php ├── UserControllerTest.php └── VacationPropertyControllerTest.php └── webhook.png /.dockerignore: -------------------------------------------------------------------------------- 1 | vendor 2 | node_modules 3 | .sqlite 4 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | APP_ENV=local 2 | APP_DEBUG=false 3 | APP_KEY=SomeRandomStringSomeRandomString 4 | 5 | # Twilio API credentials 6 | # Found at https://www.twilio.com/user/account/voice 7 | TWILIO_ACCOUNT_SID=ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 8 | TWILIO_AUTH_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 9 | 10 | # Twilio phone number 11 | # Purchase one at https://www.twilio.com/user/account/phone-numbers 12 | TWILIO_NUMBER=+15552737123 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.css linguist-vendored 3 | *.less linguist-vendored 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: composer 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 8 | ignore: 9 | - dependency-name: twilio/sdk 10 | versions: 11 | - 6.16.1 12 | -------------------------------------------------------------------------------- /.github/workflows/laravel.yml: -------------------------------------------------------------------------------- 1 | name: Laravel 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ${{ matrix.platform }} 13 | strategy: 14 | max-parallel: 3 15 | matrix: 16 | platform: [windows-latest, macos-latest, ubuntu-latest] 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | - name: Setup PHP 21 | uses: shivammathur/setup-php@v2 22 | with: 23 | php-version: 7.4 24 | extensions: mbstring, fileinfo, pdo_sqlite 25 | coverage: none 26 | - name: Copy .env 27 | run: php -r "file_exists('.env') || copy('.env.example', '.env');" 28 | - name: Install Dependencies 29 | run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist 30 | - name: Generate key 31 | run: php artisan key:generate --force 32 | - name: Directory Permissions 33 | run: chmod -R 777 storage bootstrap/cache 34 | - name: Execute tests (Unit and Feature tests) via PHPUnit 35 | run: vendor/bin/phpunit 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | /node_modules 3 | Homestead.yaml 4 | Homestead.json 5 | .env 6 | *.DS_Store 7 | .phpunit.result.cache 8 | -------------------------------------------------------------------------------- /.mergify.yml: -------------------------------------------------------------------------------- 1 | pull_request_rules: 2 | - name: automatic merge for Dependabot pull requests 3 | conditions: 4 | - author=dependabot-preview[bot] 5 | - status-success=build (macos-latest) 6 | - status-success=build (windows-latest) 7 | - status-success=build (ubuntu-latest) 8 | actions: 9 | merge: 10 | method: squash 11 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | - Using welcoming and inclusive language 18 | - Being respectful of differing viewpoints and experiences 19 | - Gracefully accepting constructive criticism 20 | - Focusing on what is best for the community 21 | - Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | - The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | - Trolling, insulting/derogatory comments, and personal or political attacks 28 | - Public or private harassment 29 | - Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | - Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at open-source@twilio.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Twilio 2 | 3 | All third party contributors acknowledge that any contributions they provide will be made under the same open source license that the open source project is provided under. 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.4 2 | 3 | WORKDIR /usr/src/app 4 | 5 | RUN apt-get update && \ 6 | apt-get upgrade -y && \ 7 | apt-get install -y git 8 | RUN apt-get install -y zip unzip 9 | 10 | COPY composer* ./ 11 | RUN curl --silent --show-error https://getcomposer.org/installer | php 12 | RUN mv composer.phar /usr/local/bin/composer 13 | 14 | 15 | COPY . . 16 | RUN make install 17 | 18 | EXPOSE 8000 19 | 20 | CMD [ "php", "artisan", "serve", "--host=0.0.0.0" ] 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Twilio Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: install serve 2 | 3 | install: 4 | touch database/database.sqlite 5 | composer install 6 | php artisan key:generate --force 7 | php artisan migrate --force 8 | 9 | serve-setup: 10 | php artisan serve --host=127.0.0.1 11 | open-browser: 12 | python3 -m webbrowser "http://127.0.0.1:8000"; 13 | serve: open-browser serve-setup 14 | -------------------------------------------------------------------------------- /app/Console/Commands/Inspire.php: -------------------------------------------------------------------------------- 1 | comment(PHP_EOL.Inspiring::quote().PHP_EOL); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | command('inspire') 28 | ->hourly(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Events/Event.php: -------------------------------------------------------------------------------- 1 | getMessage(), $e); 49 | } 50 | 51 | return parent::render($request, $e); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/AuthController.php: -------------------------------------------------------------------------------- 1 | middleware('guest', ['except' => 'getLogout']); 34 | } 35 | 36 | /** 37 | * Get a validator for an incoming registration request. 38 | * 39 | * @param array $data 40 | * @return \Illuminate\Contracts\Validation\Validator 41 | */ 42 | protected function validator(array $data) 43 | { 44 | return Validator::make($data, [ 45 | 'name' => 'required|max:255', 46 | 'email' => 'required|email|max:255|unique:users', 47 | 'password' => 'required|confirmed|min:6', 48 | ]); 49 | } 50 | 51 | /** 52 | * Create a new user instance after a valid registration. 53 | * 54 | * @param array $data 55 | * @return User 56 | */ 57 | protected function create(array $data) 58 | { 59 | return User::create([ 60 | 'name' => $data['name'], 61 | 'email' => $data['email'], 62 | 'password' => bcrypt($data['password']), 63 | ]); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/PasswordController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | validate( 24 | $request, [ 25 | 'message' => 'required|string' 26 | ] 27 | ); 28 | $property = VacationProperty::find($id); 29 | $reservation = new Reservation($request->all()); 30 | $reservation->respond_phone_number = $user->fullNumber(); 31 | $reservation->user()->associate($property->user); 32 | 33 | $property->reservations()->save($reservation); 34 | 35 | $this->notifyHost($client, $reservation); 36 | 37 | $request->session()->flash( 38 | 'status', 39 | "Sending your reservation request now." 40 | ); 41 | return redirect()->route('property-show', ['id' => $property->id]); 42 | } 43 | 44 | public function acceptReject(Request $request) 45 | { 46 | $hostNumber = $request->input('From'); 47 | $smsInput = strtolower($request->input('Body')); 48 | 49 | $host = User::getUsersByFullNumber($hostNumber)->first(); 50 | $reservation = $host->pendingReservations()->first(); 51 | 52 | $smsResponse = null; 53 | 54 | if (!is_null($reservation)) 55 | { 56 | if (strpos($smsInput, 'yes') !== false || strpos($smsInput, 'accept') !== false) 57 | { 58 | $reservation->confirm(); 59 | } 60 | else 61 | { 62 | $reservation->reject(); 63 | } 64 | 65 | $smsResponse = 'You have successfully ' . $reservation->status . ' the reservation.'; 66 | } 67 | else 68 | { 69 | $smsResponse = 'Sorry, it looks like you don\'t have any reservations to respond to.'; 70 | } 71 | 72 | return response($this->respond($smsResponse, $reservation))->header('Content-Type', 'application/xml'); 73 | } 74 | 75 | private function respond($smsResponse, $reservation) 76 | { 77 | $response = new MessagingResponse(); 78 | $response->message($smsResponse); 79 | 80 | if (!is_null($reservation)) 81 | { 82 | $response->message( 83 | 'Your reservation has been ' . $reservation->status . '.', 84 | ['to' => $reservation->respond_phone_number] 85 | ); 86 | } 87 | return $response; 88 | } 89 | 90 | private function notifyHost($client, $reservation) 91 | { 92 | $host = $reservation->property->user; 93 | 94 | $twilioNumber = config('services.twilio')['number']; 95 | $messageBody = $reservation->message . ' - Reply \'yes\' or \'accept\' to confirm the reservation, or anything else to reject it.'; 96 | 97 | try { 98 | $client->messages->create( 99 | $host->fullNumber(), // Text any number 100 | [ 101 | 'from' => $twilioNumber, // From a Twilio number in your account 102 | 'body' => $messageBody 103 | ] 104 | ); 105 | } catch (Exception $e) { 106 | Log::error($e->getMessage()); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /app/Http/Controllers/SessionController.php: -------------------------------------------------------------------------------- 1 | input('email'); 15 | $password = $request->input('password'); 16 | 17 | if (Auth::attempt(['email' => $email, 'password' => $password], true)) 18 | { 19 | return redirect()->route('home'); 20 | } 21 | return view('login', ['errors' => new MessageBag(['Invalid username or password'])]); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/Http/Controllers/UserController.php: -------------------------------------------------------------------------------- 1 | validate( 22 | $request, [ 23 | 'name' => 'required|string', 24 | 'email' => 'required|unique:users|email', 25 | 'password' => 'required', 26 | 'country_code' => 'required', 27 | 'phone_number' => 'required|numeric' 28 | ] 29 | ); 30 | 31 | $values = $request->all(); 32 | $values['password'] = Hash::make($values['password']); 33 | 34 | $newUser = new User($values); 35 | $newUser->save(); 36 | 37 | Auth::login($newUser); 38 | 39 | $request->session()->flash( 40 | 'status', 41 | "User created successfully" 42 | ); 43 | return redirect()->route('home'); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/Http/Controllers/VacationPropertyController.php: -------------------------------------------------------------------------------- 1 | validate( 20 | $request, [ 21 | 'description' => 'required|string', 22 | 'image_url' => 'required|url' 23 | ] 24 | ); 25 | 26 | $newProperty = new VacationProperty($request->all()); 27 | $user->properties()->save($newProperty); 28 | 29 | $request->session()->flash( 30 | 'status', 31 | "Property successfully created" 32 | ); 33 | return redirect()->route('property-index'); 34 | } 35 | 36 | public function index() 37 | { 38 | $properties = VacationProperty::All(); 39 | return view('property.index', ['properties' => $properties]); 40 | } 41 | 42 | public function show($id) 43 | { 44 | $property = VacationProperty::find($id); 45 | 46 | return view('property.show', ['property' => $property]); 47 | } 48 | 49 | public function editForm($id) 50 | { 51 | $property = VacationProperty::find($id); 52 | 53 | return view('property.edit', ['property' => $property]); 54 | } 55 | 56 | public function editProperty(Request $request, $id) { 57 | $property = VacationProperty::find($id); 58 | $property->update($request->all()); 59 | 60 | return redirect()->route('property-show', ['id' => $id]); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/Http/Kernel.php: -------------------------------------------------------------------------------- 1 | [ 31 | \App\Http\Middleware\EncryptCookies::class, 32 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 33 | \Illuminate\Session\Middleware\StartSession::class, 34 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, 35 | \App\Http\Middleware\VerifyCsrfToken::class, 36 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 37 | ], 38 | 39 | 'api' => [ 40 | 'throttle:60,1', 41 | 'bindings', 42 | ], 43 | ]; 44 | 45 | /** 46 | * The application's route middleware. 47 | * 48 | * These middleware may be assigned to groups or used individually. 49 | * 50 | * @var array 51 | */ 52 | protected $routeMiddleware = [ 53 | 'auth' => \App\Http\Middleware\Authenticate::class, 54 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 55 | 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 56 | 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 57 | 'can' => \Illuminate\Auth\Middleware\Authorize::class, 58 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 59 | 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 60 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 61 | 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, 62 | ]; 63 | 64 | /** 65 | * The priority-sorted list of middleware. 66 | * 67 | * This forces non-global middleware to always be in the given order. 68 | * 69 | * @var array 70 | */ 71 | protected $middlewarePriority = [ 72 | \Illuminate\Session\Middleware\StartSession::class, 73 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, 74 | \App\Http\Middleware\Authenticate::class, 75 | \Illuminate\Session\Middleware\AuthenticateSession::class, 76 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 77 | \Illuminate\Auth\Middleware\Authorize::class, 78 | ]; 79 | } 80 | -------------------------------------------------------------------------------- /app/Http/Middleware/Authenticate.php: -------------------------------------------------------------------------------- 1 | auth = $auth; 26 | } 27 | 28 | /** 29 | * Handle an incoming request. 30 | * 31 | * @param \Illuminate\Http\Request $request 32 | * @param \Closure $next 33 | * @return mixed 34 | */ 35 | public function handle($request, Closure $next) 36 | { 37 | if ($this->auth->guest()) { 38 | if ($request->ajax()) { 39 | return response('Unauthorized.', 401); 40 | } else { 41 | return redirect()->guest('auth/login'); 42 | } 43 | } 44 | 45 | return $next($request); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/Http/Middleware/CheckForMaintenanceMode.php: -------------------------------------------------------------------------------- 1 | auth = $auth; 26 | } 27 | 28 | /** 29 | * Handle an incoming request. 30 | * 31 | * @param \Illuminate\Http\Request $request 32 | * @param \Closure $next 33 | * @return mixed 34 | */ 35 | public function handle($request, Closure $next) 36 | { 37 | if ($this->auth->check()) { 38 | return redirect('/home'); 39 | } 40 | 41 | return $next($request); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrimStrings.php: -------------------------------------------------------------------------------- 1 | 'App\Policies\ModelPolicy', 17 | ]; 18 | 19 | /** 20 | * Register any application authentication / authorization services. 21 | * 22 | * @param \Illuminate\Contracts\Auth\Access\Gate $gate 23 | * @return void 24 | */ 25 | public function boot(GateContract $gate) 26 | { 27 | $this->registerPolicies($gate); 28 | 29 | // 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/Providers/BroadcastServiceProvider.php: -------------------------------------------------------------------------------- 1 | mapApiRoutes(); 39 | 40 | $this->mapWebRoutes(); 41 | 42 | // 43 | } 44 | 45 | /** 46 | * Define the "web" routes for the application. 47 | * 48 | * These routes all receive session state, CSRF protection, etc. 49 | * 50 | * @return void 51 | */ 52 | protected function mapWebRoutes() 53 | { 54 | Route::middleware('web') 55 | ->namespace($this->namespace) 56 | ->group(base_path('routes/web.php')); 57 | } 58 | 59 | /** 60 | * Define the "api" routes for the application. 61 | * 62 | * These routes are typically stateless. 63 | * 64 | * @return void 65 | */ 66 | protected function mapApiRoutes() 67 | { 68 | Route::prefix('api') 69 | ->middleware('api') 70 | ->namespace($this->namespace) 71 | ->group(base_path('routes/api.php')); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /app/Providers/TwilioRestClientProvider.php: -------------------------------------------------------------------------------- 1 | app->bind( 16 | Client::class, function ($app) { 17 | $accountSid = config('services.twilio')['accountSid']; 18 | $authToken = config('services.twilio')['authToken']; 19 | return new Client($accountSid, $authToken); 20 | } 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/Reservation.php: -------------------------------------------------------------------------------- 1 | belongsTo('App\VacationProperty', 'vacation_property_id'); 29 | } 30 | 31 | /** 32 | * Get the user for this reservation. 33 | */ 34 | public function user() 35 | { 36 | return $this->belongsTo('App\User'); 37 | } 38 | 39 | public function confirm() 40 | { 41 | $this->status = 'confirmed'; 42 | $this->save(); 43 | } 44 | 45 | public function reject() 46 | { 47 | $this->status = 'rejected'; 48 | $this->save(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/User.php: -------------------------------------------------------------------------------- 1 | hasMany('App\VacationProperty'); 47 | } 48 | 49 | public function propertyReservations() 50 | { 51 | return $this->hasManyThrough('App\Reservation', 'App\VacationProperty', 'user_id', 'vacation_property_id'); 52 | } 53 | 54 | public function reservations() 55 | { 56 | return $this->hasMany('App\Reservation'); 57 | } 58 | 59 | public function pendingReservations() 60 | { 61 | return $this->propertyReservations()->where('status', '=', 'pending'); 62 | } 63 | 64 | public function fullNumber() 65 | { 66 | return '+' . $this->country_code . $this->phone_number; 67 | } 68 | 69 | public static function getUsersByFullNumber($number) 70 | { 71 | $connection = config('database.default'); 72 | $driver = config("database.connections.{$connection}.driver"); 73 | if ($driver === 'sqlite') { 74 | $concat_string = DB::raw("'+' || country_code || phone_number"); 75 | } else { 76 | $concat_string = DB::raw("CONCAT('+',country_code::text, phone_number::text)"); 77 | } 78 | 79 | return self::where($concat_string, 'LIKE', "%".$number."%")->get(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /app/VacationProperty.php: -------------------------------------------------------------------------------- 1 | belongsTo('App\User'); 29 | } 30 | 31 | public function reservations() 32 | { 33 | return $this->hasMany('App\Reservation'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /artisan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | make(Illuminate\Contracts\Console\Kernel::class); 32 | 33 | $status = $kernel->handle( 34 | $input = new Symfony\Component\Console\Input\ArgvInput, 35 | new Symfony\Component\Console\Output\ConsoleOutput 36 | ); 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Shutdown The Application 41 | |-------------------------------------------------------------------------- 42 | | 43 | | Once Artisan has finished running. We will fire off the shutdown events 44 | | so that any final work may be done by the application before we shut 45 | | down the process. This is the last thing to happen to the request. 46 | | 47 | */ 48 | 49 | $kernel->terminate($input, $status); 50 | 51 | exit($status); 52 | -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | singleton( 30 | Illuminate\Contracts\Http\Kernel::class, 31 | App\Http\Kernel::class 32 | ); 33 | 34 | $app->singleton( 35 | Illuminate\Contracts\Console\Kernel::class, 36 | App\Console\Kernel::class 37 | ); 38 | 39 | $app->singleton( 40 | Illuminate\Contracts\Debug\ExceptionHandler::class, 41 | App\Exceptions\Handler::class 42 | ); 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Return The Application 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This script returns the application instance. The instance is given to 50 | | the calling script so we can separate the building of the instances 51 | | from the actual running of the application and sending responses. 52 | | 53 | */ 54 | 55 | return $app; 56 | -------------------------------------------------------------------------------- /bootstrap/autoload.php: -------------------------------------------------------------------------------- 1 | env('APP_NAME', 'Laravel'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Application Environment 21 | |-------------------------------------------------------------------------- 22 | | 23 | | This value determines the "environment" your application is currently 24 | | running in. This may determine how you prefer to configure various 25 | | services the application utilizes. Set this in your ".env" file. 26 | | 27 | */ 28 | 29 | 'env' => env('APP_ENV', 'production'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Application Debug Mode 34 | |-------------------------------------------------------------------------- 35 | | 36 | | When your application is in debug mode, detailed error messages with 37 | | stack traces will be shown on every error that occurs within your 38 | | application. If disabled, a simple generic error page is shown. 39 | | 40 | */ 41 | 42 | 'debug' => env('APP_DEBUG', false), 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Application URL 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This URL is used by the console to properly generate URLs when using 50 | | the Artisan command line tool. You should set this to the root of 51 | | your application so that it is used when running Artisan tasks. 52 | | 53 | */ 54 | 55 | 'url' => 'http://localhost', 56 | 57 | /* 58 | |-------------------------------------------------------------------------- 59 | | Application Timezone 60 | |-------------------------------------------------------------------------- 61 | | 62 | | Here you may specify the default timezone for your application, which 63 | | will be used by the PHP date and date-time functions. We have gone 64 | | ahead and set this to a sensible default for you out of the box. 65 | | 66 | */ 67 | 68 | 'timezone' => 'UTC', 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Application Locale Configuration 73 | |-------------------------------------------------------------------------- 74 | | 75 | | The application locale determines the default locale that will be used 76 | | by the translation service provider. You are free to set this value 77 | | to any of the locales which will be supported by the application. 78 | | 79 | */ 80 | 81 | 'locale' => 'en', 82 | 83 | /* 84 | |-------------------------------------------------------------------------- 85 | | Application Fallback Locale 86 | |-------------------------------------------------------------------------- 87 | | 88 | | The fallback locale determines the locale to use when the current one 89 | | is not available. You may change the value to correspond to any of 90 | | the language folders that are provided through your application. 91 | | 92 | */ 93 | 94 | 'fallback_locale' => 'en', 95 | 96 | /* 97 | |-------------------------------------------------------------------------- 98 | | Encryption Key 99 | |-------------------------------------------------------------------------- 100 | | 101 | | This key is used by the Illuminate encrypter service and should be set 102 | | to a random, 32 character string, otherwise these encrypted strings 103 | | will not be safe. Please do this before deploying an application! 104 | | 105 | */ 106 | 107 | 'key' => env('APP_KEY', 'SomeRandomString'), 108 | 109 | 'cipher' => 'AES-256-CBC', 110 | 111 | /* 112 | |-------------------------------------------------------------------------- 113 | | Logging Configuration 114 | |-------------------------------------------------------------------------- 115 | | 116 | | Here you may configure the log settings for your application. Out of 117 | | the box, Laravel uses the Monolog PHP logging library. This gives 118 | | you a variety of powerful log handlers / formatters to utilize. 119 | | 120 | | Available Settings: "single", "daily", "syslog", "errorlog" 121 | | 122 | */ 123 | 124 | 'log' => 'single', 125 | 126 | /* 127 | |-------------------------------------------------------------------------- 128 | | Autoloaded Service Providers 129 | |-------------------------------------------------------------------------- 130 | | 131 | | The service providers listed here will be automatically loaded on the 132 | | request to your application. Feel free to add your own services to 133 | | this array to grant expanded functionality to your applications. 134 | | 135 | */ 136 | 137 | 'providers' => [ 138 | Collective\Html\HtmlServiceProvider::class, 139 | /* 140 | * Laravel Framework Service Providers... 141 | */ 142 | Illuminate\Auth\AuthServiceProvider::class, 143 | Illuminate\Broadcasting\BroadcastServiceProvider::class, 144 | Illuminate\Bus\BusServiceProvider::class, 145 | Illuminate\Cache\CacheServiceProvider::class, 146 | Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, 147 | Illuminate\Cookie\CookieServiceProvider::class, 148 | Illuminate\Database\DatabaseServiceProvider::class, 149 | Illuminate\Encryption\EncryptionServiceProvider::class, 150 | Illuminate\Filesystem\FilesystemServiceProvider::class, 151 | Illuminate\Foundation\Providers\FoundationServiceProvider::class, 152 | Illuminate\Hashing\HashServiceProvider::class, 153 | Illuminate\Mail\MailServiceProvider::class, 154 | Illuminate\Pagination\PaginationServiceProvider::class, 155 | Illuminate\Pipeline\PipelineServiceProvider::class, 156 | Illuminate\Queue\QueueServiceProvider::class, 157 | Illuminate\Redis\RedisServiceProvider::class, 158 | Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, 159 | Illuminate\Session\SessionServiceProvider::class, 160 | Illuminate\Translation\TranslationServiceProvider::class, 161 | Illuminate\Validation\ValidationServiceProvider::class, 162 | Illuminate\View\ViewServiceProvider::class, 163 | Illuminate\Foundation\Support\Providers\EventServiceProvider::class, 164 | 165 | /* 166 | * Application Service Providers... 167 | */ 168 | App\Providers\AppServiceProvider::class, 169 | App\Providers\RouteServiceProvider::class, 170 | App\Providers\AuthServiceProvider::class, 171 | App\Providers\TwilioRestClientProvider::class, 172 | 173 | ], 174 | 175 | /* 176 | |-------------------------------------------------------------------------- 177 | | Class Aliases 178 | |-------------------------------------------------------------------------- 179 | | 180 | | This array of class aliases will be registered when this application 181 | | is started. However, feel free to register as many as you wish as 182 | | the aliases are "lazy" loaded so they don't hinder performance. 183 | | 184 | */ 185 | 186 | 'aliases' => [ 187 | 188 | 'App' => Illuminate\Support\Facades\App::class, 189 | 'Artisan' => Illuminate\Support\Facades\Artisan::class, 190 | 'Auth' => Illuminate\Support\Facades\Auth::class, 191 | 'Blade' => Illuminate\Support\Facades\Blade::class, 192 | 'Bus' => Illuminate\Support\Facades\Bus::class, 193 | 'Cache' => Illuminate\Support\Facades\Cache::class, 194 | 'Config' => Illuminate\Support\Facades\Config::class, 195 | 'Cookie' => Illuminate\Support\Facades\Cookie::class, 196 | 'Crypt' => Illuminate\Support\Facades\Crypt::class, 197 | 'DB' => Illuminate\Support\Facades\DB::class, 198 | 'Eloquent' => Illuminate\Database\Eloquent\Model::class, 199 | 'Event' => Illuminate\Support\Facades\Event::class, 200 | 'File' => Illuminate\Support\Facades\File::class, 201 | 'Form' => Collective\Html\FormFacade::class, 202 | 'Gate' => Illuminate\Support\Facades\Gate::class, 203 | 'Hash' => Illuminate\Support\Facades\Hash::class, 204 | 'Input' => Illuminate\Support\Facades\Input::class, 205 | 'Inspiring' => Illuminate\Foundation\Inspiring::class, 206 | 'Lang' => Illuminate\Support\Facades\Lang::class, 207 | 'Log' => Illuminate\Support\Facades\Log::class, 208 | 'Mail' => Illuminate\Support\Facades\Mail::class, 209 | 'Password' => Illuminate\Support\Facades\Password::class, 210 | 'Queue' => Illuminate\Support\Facades\Queue::class, 211 | 'Redirect' => Illuminate\Support\Facades\Redirect::class, 212 | 'Redis' => Illuminate\Support\Facades\Redis::class, 213 | 'Request' => Illuminate\Support\Facades\Request::class, 214 | 'Response' => Illuminate\Support\Facades\Response::class, 215 | 'Route' => Illuminate\Support\Facades\Route::class, 216 | 'Schema' => Illuminate\Support\Facades\Schema::class, 217 | 'Session' => Illuminate\Support\Facades\Session::class, 218 | 'Storage' => Illuminate\Support\Facades\Storage::class, 219 | 'URL' => Illuminate\Support\Facades\URL::class, 220 | 'Validator' => Illuminate\Support\Facades\Validator::class, 221 | 'View' => Illuminate\Support\Facades\View::class, 222 | 223 | ], 224 | 225 | 'debug_hide' => [ 226 | '_ENV' => [ 227 | 'APP_KEY', 228 | 'TWILIO_ACCOUNT_SID', 229 | 'TWILIO_AUTH_TOKEN', 230 | ], 231 | 232 | '_SERVER' => [ 233 | 'APP_KEY', 234 | 'TWILIO_ACCOUNT_SID', 235 | 'TWILIO_AUTH_TOKEN', 236 | ], 237 | ], 238 | ]; 239 | -------------------------------------------------------------------------------- /config/auth.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'guard' => 'web', 18 | 'passwords' => 'users', 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Authentication Guards 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Next, you may define every authentication guard for your application. 27 | | Of course, a great default configuration has been defined for you 28 | | here which uses session storage and the Eloquent user provider. 29 | | 30 | | All authentication drivers have a user provider. This defines how the 31 | | users are actually retrieved out of your database or other storage 32 | | mechanisms used by this application to persist your user's data. 33 | | 34 | | Supported: "session", "token" 35 | | 36 | */ 37 | 38 | 'guards' => [ 39 | 'web' => [ 40 | 'driver' => 'session', 41 | 'provider' => 'users', 42 | ], 43 | 44 | 'api' => [ 45 | 'driver' => 'token', 46 | 'provider' => 'users', 47 | ], 48 | ], 49 | 50 | /* 51 | |-------------------------------------------------------------------------- 52 | | User Providers 53 | |-------------------------------------------------------------------------- 54 | | 55 | | All authentication drivers have a user provider. This defines how the 56 | | users are actually retrieved out of your database or other storage 57 | | mechanisms used by this application to persist your user's data. 58 | | 59 | | If you have multiple user tables or models you may configure multiple 60 | | sources which represent each model / table. These sources may then 61 | | be assigned to any extra authentication guards you have defined. 62 | | 63 | | Supported: "database", "eloquent" 64 | | 65 | */ 66 | 67 | 'providers' => [ 68 | 'users' => [ 69 | 'driver' => 'eloquent', 70 | 'model' => App\User::class, 71 | ], 72 | ], 73 | 74 | /* 75 | |-------------------------------------------------------------------------- 76 | | Resetting Passwords 77 | |-------------------------------------------------------------------------- 78 | | 79 | | Here you may set the options for resetting passwords including the view 80 | | that is your password reset e-mail. You may also set the name of the 81 | | table that maintains all of the reset tokens for your application. 82 | | 83 | | You may specify multiple password reset configurations if you have more 84 | | than one user table or model in the application and you want to have 85 | | separate password reset settings based on the specific user types. 86 | | 87 | | The expire time is the number of minutes that the reset token should be 88 | | considered valid. This security feature keeps tokens short-lived so 89 | | they have less time to be guessed. You may change this as needed. 90 | | 91 | */ 92 | 93 | 'passwords' => [ 94 | 'users' => [ 95 | 'provider' => 'users', 96 | 'email' => 'auth.emails.password', 97 | 'table' => 'password_resets', 98 | 'expire' => 60, 99 | ], 100 | ], 101 | 102 | ]; 103 | -------------------------------------------------------------------------------- /config/broadcasting.php: -------------------------------------------------------------------------------- 1 | env('BROADCAST_DRIVER', 'pusher'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Broadcast Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may define all of the broadcast connections that will be used 24 | | to broadcast events to other systems or over websockets. Samples of 25 | | each available type of connection are provided inside this array. 26 | | 27 | */ 28 | 29 | 'connections' => [ 30 | 31 | 'pusher' => [ 32 | 'driver' => 'pusher', 33 | 'key' => env('PUSHER_KEY'), 34 | 'secret' => env('PUSHER_SECRET'), 35 | 'app_id' => env('PUSHER_APP_ID'), 36 | 'options' => [ 37 | // 38 | ], 39 | ], 40 | 41 | 'redis' => [ 42 | 'driver' => 'redis', 43 | 'connection' => 'default', 44 | ], 45 | 46 | 'log' => [ 47 | 'driver' => 'log', 48 | ], 49 | 50 | ], 51 | 52 | ]; 53 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_DRIVER', 'file'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Cache Stores 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may define all of the cache "stores" for your application as 24 | | well as their drivers. You may even define multiple stores for the 25 | | same cache driver to group types of items stored in your caches. 26 | | 27 | */ 28 | 29 | 'stores' => [ 30 | 31 | 'apc' => [ 32 | 'driver' => 'apc', 33 | ], 34 | 35 | 'array' => [ 36 | 'driver' => 'array', 37 | ], 38 | 39 | 'database' => [ 40 | 'driver' => 'database', 41 | 'table' => 'cache', 42 | 'connection' => null, 43 | ], 44 | 45 | 'file' => [ 46 | 'driver' => 'file', 47 | 'path' => storage_path('framework/cache'), 48 | ], 49 | 50 | 'memcached' => [ 51 | 'driver' => 'memcached', 52 | 'servers' => [ 53 | [ 54 | 'host' => '127.0.0.1', 'port' => 11211, 'weight' => 100, 55 | ], 56 | ], 57 | ], 58 | 59 | 'redis' => [ 60 | 'driver' => 'redis', 61 | 'connection' => 'default', 62 | ], 63 | 64 | ], 65 | 66 | /* 67 | |-------------------------------------------------------------------------- 68 | | Cache Key Prefix 69 | |-------------------------------------------------------------------------- 70 | | 71 | | When utilizing a RAM based store such as APC or Memcached, there might 72 | | be other applications utilizing the same cache. So, we'll specify a 73 | | value to get prefixed to all our keys so we can avoid collisions. 74 | | 75 | */ 76 | 77 | 'prefix' => 'laravel', 78 | 79 | ]; 80 | -------------------------------------------------------------------------------- /config/compile.php: -------------------------------------------------------------------------------- 1 | [ 17 | // 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled File Providers 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may list service providers which define a "compiles" function 26 | | that returns additional files that should be compiled, providing an 27 | | easy way to get common files from any packages you are utilizing. 28 | | 29 | */ 30 | 31 | 'providers' => [ 32 | // 33 | ], 34 | 35 | ]; 36 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | PDO::FETCH_CLASS, 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Default Database Connection Name 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may specify which of the database connections below you wish 24 | | to use as your default connection for all database work. Of course 25 | | you may use many connections at once using the Database library. 26 | | 27 | */ 28 | 29 | 'default' => env('DB_CONNECTION', 'sqlite'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Database Connections 34 | |-------------------------------------------------------------------------- 35 | | 36 | | Here are each of the database connections setup for your application. 37 | | Of course, examples of configuring each database platform that is 38 | | supported by Laravel is shown below to make development simple. 39 | | 40 | | 41 | | All database work in Laravel is done through the PHP PDO facilities 42 | | so make sure you have the driver for your particular database of 43 | | choice installed on your machine before you begin development. 44 | | 45 | */ 46 | 47 | 'connections' => [ 48 | 49 | 'sqlite' => [ 50 | 'driver' => 'sqlite', 51 | 'database' => database_path('database.sqlite'), 52 | 'prefix' => '', 53 | ], 54 | 55 | 'testing' => [ 56 | 'driver' => 'sqlite', 57 | 'database' => ':memory:', 58 | 'prefix' => '', 59 | ], 60 | 61 | 'mysql' => [ 62 | 'driver' => 'mysql', 63 | 'host' => env('DB_HOST', 'localhost'), 64 | 'database' => env('DB_DATABASE', 'forge'), 65 | 'username' => env('DB_USERNAME', 'forge'), 66 | 'password' => env('DB_PASSWORD', ''), 67 | 'charset' => 'utf8', 68 | 'collation' => 'utf8_unicode_ci', 69 | 'prefix' => '', 70 | 'strict' => false, 71 | ], 72 | 73 | 'pgsql' => [ 74 | 'driver' => 'pgsql', 75 | 'host' => env('DB_HOST', 'localhost'), 76 | 'database' => env('DB_DATABASE', 'forge'), 77 | 'username' => env('DB_USERNAME', ''), 78 | 'password' => env('DB_PASSWORD', ''), 79 | 'charset' => 'utf8', 80 | 'prefix' => '', 81 | 'schema' => 'public', 82 | ], 83 | 84 | 'sqlsrv' => [ 85 | 'driver' => 'sqlsrv', 86 | 'host' => env('DB_HOST', 'localhost'), 87 | 'database' => env('DB_DATABASE', 'forge'), 88 | 'username' => env('DB_USERNAME', 'forge'), 89 | 'password' => env('DB_PASSWORD', ''), 90 | 'charset' => 'utf8', 91 | 'prefix' => '', 92 | ], 93 | 94 | ], 95 | 96 | /* 97 | |-------------------------------------------------------------------------- 98 | | Migration Repository Table 99 | |-------------------------------------------------------------------------- 100 | | 101 | | This table keeps track of all the migrations that have already run for 102 | | your application. Using this information, we can determine which of 103 | | the migrations on disk haven't actually been run in the database. 104 | | 105 | */ 106 | 107 | 'migrations' => 'migrations', 108 | 109 | /* 110 | |-------------------------------------------------------------------------- 111 | | Redis Databases 112 | |-------------------------------------------------------------------------- 113 | | 114 | | Redis is an open source, fast, and advanced key-value store that also 115 | | provides a richer set of commands than a typical key-value systems 116 | | such as APC or Memcached. Laravel makes it easy to dig right in. 117 | | 118 | */ 119 | 120 | 'redis' => [ 121 | 122 | 'cluster' => false, 123 | 124 | 'default' => [ 125 | 'host' => '127.0.0.1', 126 | 'port' => 6379, 127 | 'database' => 0, 128 | ], 129 | 130 | ], 131 | 132 | ]; 133 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | 'local', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Default Cloud Filesystem Disk 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Many applications store files both locally and in the cloud. For this 26 | | reason, you may specify a default "cloud" driver here. This driver 27 | | will be bound as the Cloud disk implementation in the container. 28 | | 29 | */ 30 | 31 | 'cloud' => 's3', 32 | 33 | /* 34 | |-------------------------------------------------------------------------- 35 | | Filesystem Disks 36 | |-------------------------------------------------------------------------- 37 | | 38 | | Here you may configure as many filesystem "disks" as you wish, and you 39 | | may even configure multiple disks of the same driver. Defaults have 40 | | been setup for each driver as an example of the required options. 41 | | 42 | */ 43 | 44 | 'disks' => [ 45 | 46 | 'local' => [ 47 | 'driver' => 'local', 48 | 'root' => storage_path('app'), 49 | ], 50 | 51 | 'ftp' => [ 52 | 'driver' => 'ftp', 53 | 'host' => 'ftp.example.com', 54 | 'username' => 'your-username', 55 | 'password' => 'your-password', 56 | 57 | // Optional FTP Settings... 58 | // 'port' => 21, 59 | // 'root' => '', 60 | // 'passive' => true, 61 | // 'ssl' => true, 62 | // 'timeout' => 30, 63 | ], 64 | 65 | 's3' => [ 66 | 'driver' => 's3', 67 | 'key' => 'your-key', 68 | 'secret' => 'your-secret', 69 | 'region' => 'your-region', 70 | 'bucket' => 'your-bucket', 71 | ], 72 | 73 | 'rackspace' => [ 74 | 'driver' => 'rackspace', 75 | 'username' => 'your-username', 76 | 'key' => 'your-key', 77 | 'container' => 'your-container', 78 | 'endpoint' => 'https://identity.api.rackspacecloud.com/v2.0/', 79 | 'region' => 'IAD', 80 | 'url_type' => 'publicURL', 81 | ], 82 | 83 | ], 84 | 85 | ]; 86 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_DRIVER', 'smtp'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | SMTP Host Address 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may provide the host address of the SMTP server used by your 26 | | applications. A default option is provided that is compatible with 27 | | the Mailgun mail service which will provide reliable deliveries. 28 | | 29 | */ 30 | 31 | 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 32 | 33 | /* 34 | |-------------------------------------------------------------------------- 35 | | SMTP Host Port 36 | |-------------------------------------------------------------------------- 37 | | 38 | | This is the SMTP port used by your application to deliver e-mails to 39 | | users of the application. Like the host we have set this value to 40 | | stay compatible with the Mailgun e-mail application by default. 41 | | 42 | */ 43 | 44 | 'port' => env('MAIL_PORT', 587), 45 | 46 | /* 47 | |-------------------------------------------------------------------------- 48 | | Global "From" Address 49 | |-------------------------------------------------------------------------- 50 | | 51 | | You may wish for all e-mails sent by your application to be sent from 52 | | the same address. Here, you may specify a name and address that is 53 | | used globally for all e-mails that are sent by your application. 54 | | 55 | */ 56 | 57 | 'from' => ['address' => null, 'name' => null], 58 | 59 | /* 60 | |-------------------------------------------------------------------------- 61 | | E-Mail Encryption Protocol 62 | |-------------------------------------------------------------------------- 63 | | 64 | | Here you may specify the encryption protocol that should be used when 65 | | the application send e-mail messages. A sensible default using the 66 | | transport layer security protocol should provide great security. 67 | | 68 | */ 69 | 70 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 71 | 72 | /* 73 | |-------------------------------------------------------------------------- 74 | | SMTP Server Username 75 | |-------------------------------------------------------------------------- 76 | | 77 | | If your SMTP server requires a username for authentication, you should 78 | | set it here. This will get used to authenticate with your server on 79 | | connection. You may also set the "password" value below this one. 80 | | 81 | */ 82 | 83 | 'username' => env('MAIL_USERNAME'), 84 | 85 | /* 86 | |-------------------------------------------------------------------------- 87 | | SMTP Server Password 88 | |-------------------------------------------------------------------------- 89 | | 90 | | Here you may set the password required by your SMTP server to send out 91 | | messages from your application. This will be given to the server on 92 | | connection so that the application will be able to send messages. 93 | | 94 | */ 95 | 96 | 'password' => env('MAIL_PASSWORD'), 97 | 98 | /* 99 | |-------------------------------------------------------------------------- 100 | | Sendmail System Path 101 | |-------------------------------------------------------------------------- 102 | | 103 | | When using the "sendmail" driver to send e-mails, we will need to know 104 | | the path to where Sendmail lives on this server. A default path has 105 | | been provided here, which will work well on most of your systems. 106 | | 107 | */ 108 | 109 | 'sendmail' => '/usr/sbin/sendmail -bs', 110 | 111 | /* 112 | |-------------------------------------------------------------------------- 113 | | Mail "Pretend" 114 | |-------------------------------------------------------------------------- 115 | | 116 | | When this option is enabled, e-mail will not actually be sent over the 117 | | web and will instead be written to your application's logs files so 118 | | you may inspect the message. This is great for local development. 119 | | 120 | */ 121 | 122 | 'pretend' => false, 123 | 124 | ]; 125 | -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_DRIVER', 'sync'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Queue Connections 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may configure the connection information for each server that 27 | | is used by your application. A default configuration has been added 28 | | for each back-end shipped with Laravel. You are free to add more. 29 | | 30 | */ 31 | 32 | 'connections' => [ 33 | 34 | 'sync' => [ 35 | 'driver' => 'sync', 36 | ], 37 | 38 | 'database' => [ 39 | 'driver' => 'database', 40 | 'table' => 'jobs', 41 | 'queue' => 'default', 42 | 'expire' => 60, 43 | ], 44 | 45 | 'beanstalkd' => [ 46 | 'driver' => 'beanstalkd', 47 | 'host' => 'localhost', 48 | 'queue' => 'default', 49 | 'ttr' => 60, 50 | ], 51 | 52 | 'sqs' => [ 53 | 'driver' => 'sqs', 54 | 'key' => 'your-public-key', 55 | 'secret' => 'your-secret-key', 56 | 'queue' => 'your-queue-url', 57 | 'region' => 'us-east-1', 58 | ], 59 | 60 | 'iron' => [ 61 | 'driver' => 'iron', 62 | 'host' => 'mq-aws-us-east-1.iron.io', 63 | 'token' => 'your-token', 64 | 'project' => 'your-project-id', 65 | 'queue' => 'your-queue-name', 66 | 'encrypt' => true, 67 | ], 68 | 69 | 'redis' => [ 70 | 'driver' => 'redis', 71 | 'connection' => 'default', 72 | 'queue' => 'default', 73 | 'expire' => 60, 74 | ], 75 | 76 | ], 77 | 78 | /* 79 | |-------------------------------------------------------------------------- 80 | | Failed Queue Jobs 81 | |-------------------------------------------------------------------------- 82 | | 83 | | These options configure the behavior of failed queue job logging so you 84 | | can control which database and table are used to store the jobs that 85 | | have failed. You may change them to any database / table you wish. 86 | | 87 | */ 88 | 89 | 'failed' => [ 90 | 'database' => env('DB_CONNECTION', 'mysql'), 91 | 'table' => 'failed_jobs', 92 | ], 93 | 94 | ]; 95 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'accountSid' => env('TWILIO_ACCOUNT_SID'), 19 | 'authToken' => env('TWILIO_AUTH_TOKEN'), 20 | 'number' => env('TWILIO_NUMBER') 21 | ] 22 | 23 | ]; 24 | -------------------------------------------------------------------------------- /config/session.php: -------------------------------------------------------------------------------- 1 | env('SESSION_DRIVER', 'file'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Session Lifetime 26 | |-------------------------------------------------------------------------- 27 | | 28 | | Here you may specify the number of minutes that you wish the session 29 | | to be allowed to remain idle before it expires. If you want them 30 | | to immediately expire on the browser closing, set that option. 31 | | 32 | */ 33 | 34 | 'lifetime' => env('SESSION_LIFETIME', 120), 35 | 36 | 'expire_on_close' => false, 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Session Encryption 41 | |-------------------------------------------------------------------------- 42 | | 43 | | This option allows you to easily specify that all of your session data 44 | | should be encrypted before it is stored. All encryption will be run 45 | | automatically by Laravel and you can use the Session like normal. 46 | | 47 | */ 48 | 49 | 'encrypt' => false, 50 | 51 | /* 52 | |-------------------------------------------------------------------------- 53 | | Session File Location 54 | |-------------------------------------------------------------------------- 55 | | 56 | | When using the native session driver, we need a location where session 57 | | files may be stored. A default has been set for you but a different 58 | | location may be specified. This is only needed for file sessions. 59 | | 60 | */ 61 | 62 | 'files' => storage_path('framework/sessions'), 63 | 64 | /* 65 | |-------------------------------------------------------------------------- 66 | | Session Database Connection 67 | |-------------------------------------------------------------------------- 68 | | 69 | | When using the "database" or "redis" session drivers, you may specify a 70 | | connection that should be used to manage these sessions. This should 71 | | correspond to a connection in your database configuration options. 72 | | 73 | */ 74 | 75 | 'connection' => env('SESSION_CONNECTION', null), 76 | 77 | /* 78 | |-------------------------------------------------------------------------- 79 | | Session Database Table 80 | |-------------------------------------------------------------------------- 81 | | 82 | | When using the "database" session driver, you may specify the table we 83 | | should use to manage the sessions. Of course, a sensible default is 84 | | provided for you; however, you are free to change this as needed. 85 | | 86 | */ 87 | 88 | 'table' => 'sessions', 89 | 90 | /* 91 | |-------------------------------------------------------------------------- 92 | | Session Cache Store 93 | |-------------------------------------------------------------------------- 94 | | 95 | | When using the "apc", "memcached", or "dynamodb" session drivers you may 96 | | list a cache store that should be used for these sessions. This value 97 | | must match with one of the application's configured cache "stores". 98 | | 99 | */ 100 | 101 | 'store' => env('SESSION_STORE', null), 102 | 103 | /* 104 | |-------------------------------------------------------------------------- 105 | | Session Sweeping Lottery 106 | |-------------------------------------------------------------------------- 107 | | 108 | | Some session drivers must manually sweep their storage location to get 109 | | rid of old sessions from storage. Here are the chances that it will 110 | | happen on a given request. By default, the odds are 2 out of 100. 111 | | 112 | */ 113 | 114 | 'lottery' => [2, 100], 115 | 116 | /* 117 | |-------------------------------------------------------------------------- 118 | | Session Cookie Name 119 | |-------------------------------------------------------------------------- 120 | | 121 | | Here you may change the name of the cookie used to identify a session 122 | | instance by ID. The name specified here will get used every time a 123 | | new session cookie is created by the framework for every driver. 124 | | 125 | */ 126 | 127 | 'cookie' => env( 128 | 'SESSION_COOKIE', 129 | Str::slug(env('APP_NAME', 'laravel'), '_').'_session' 130 | ), 131 | 132 | /* 133 | |-------------------------------------------------------------------------- 134 | | Session Cookie Path 135 | |-------------------------------------------------------------------------- 136 | | 137 | | The session cookie path determines the path for which the cookie will 138 | | be regarded as available. Typically, this will be the root path of 139 | | your application but you are free to change this when necessary. 140 | | 141 | */ 142 | 143 | 'path' => '/', 144 | 145 | /* 146 | |-------------------------------------------------------------------------- 147 | | Session Cookie Domain 148 | |-------------------------------------------------------------------------- 149 | | 150 | | Here you may change the domain of the cookie used to identify a session 151 | | in your application. This will determine which domains the cookie is 152 | | available to in your application. A sensible default has been set. 153 | | 154 | */ 155 | 156 | 'domain' => env('SESSION_DOMAIN', null), 157 | 158 | /* 159 | |-------------------------------------------------------------------------- 160 | | HTTPS Only Cookies 161 | |-------------------------------------------------------------------------- 162 | | 163 | | By setting this option to true, session cookies will only be sent back 164 | | to the server if the browser has a HTTPS connection. This will keep 165 | | the cookie from being sent to you if it can not be done securely. 166 | | 167 | */ 168 | 169 | 'secure' => env('SESSION_SECURE_COOKIE', null), 170 | 171 | /* 172 | |-------------------------------------------------------------------------- 173 | | HTTP Access Only 174 | |-------------------------------------------------------------------------- 175 | | 176 | | Setting this value to true will prevent JavaScript from accessing the 177 | | value of the cookie and the cookie will only be accessible through 178 | | the HTTP protocol. You are free to modify this option if needed. 179 | | 180 | */ 181 | 182 | 'http_only' => true, 183 | 184 | /* 185 | |-------------------------------------------------------------------------- 186 | | Same-Site Cookies 187 | |-------------------------------------------------------------------------- 188 | | 189 | | This option determines how your cookies behave when cross-site requests 190 | | take place, and can be used to mitigate CSRF attacks. By default, we 191 | | do not enable this as other CSRF protection services are in place. 192 | | 193 | | Supported: "lax", "strict", "none", null 194 | | 195 | */ 196 | 197 | 'same_site' => 'lax', 198 | 199 | ]; 200 | -------------------------------------------------------------------------------- /config/view.php: -------------------------------------------------------------------------------- 1 | [ 17 | realpath(base_path('resources/views')), 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled View Path 23 | |-------------------------------------------------------------------------- 24 | | 25 | | This option determines where all the compiled Blade templates will be 26 | | stored for your application. Typically, this is within the storage 27 | | directory. However, as usual, you are free to change this value. 28 | | 29 | */ 30 | 31 | 'compiled' => realpath(storage_path('framework/views')), 32 | 33 | ]; 34 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | -------------------------------------------------------------------------------- /database/factories/ModelFactory.php: -------------------------------------------------------------------------------- 1 | define(App\User::class, function (Faker\Generator $faker) { 15 | return [ 16 | 'name' => $faker->name, 17 | 'email' => $faker->email, 18 | 'password' => bcrypt(str_random(10)), 19 | 'remember_token' => str_random(10), 20 | ]; 21 | }); 22 | -------------------------------------------------------------------------------- /database/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TwilioDevEd/airtng-laravel/6e1a5d38c3b7a6503df8209f399cb12952028107/database/migrations/.gitkeep -------------------------------------------------------------------------------- /database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 17 | $table->string('name'); 18 | $table->string('email')->unique(); 19 | $table->string('password', 60); 20 | $table->string('phone_number'); 21 | $table->string('country_code'); 22 | $table->rememberToken(); 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::drop('users'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /database/migrations/2015_10_23_193814_create_vacation_properties_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 17 | $table->integer('user_id')->unsigned(); 18 | $table->foreign('user_id') 19 | ->references('id')->on('users') 20 | ->onDelete('cascade'); 21 | $table->string('description'); 22 | $table->string('image_url'); 23 | 24 | $table->timestamps(); 25 | }); 26 | } 27 | 28 | /** 29 | * Reverse the migrations. 30 | * 31 | * @return void 32 | */ 33 | public function down() 34 | { 35 | Schema::drop('vacation_properties'); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /database/migrations/2015_10_23_194614_create_reservations_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 17 | $table->string('status') 18 | ->default('pending'); 19 | $table->string('respond_phone_number'); 20 | $table->text('message'); 21 | $table->integer('vacation_property_id')->unsigned(); 22 | $table->foreign('vacation_property_id') 23 | ->references('id')->on('vacation_properties') 24 | ->onDelete('cascade'); 25 | $table->integer('user_id')->unsigned(); 26 | $table->foreign('user_id') 27 | ->references('id')->on('users') 28 | ->onDelete('cascade'); 29 | 30 | $table->timestamps(); 31 | }); 32 | } 33 | 34 | /** 35 | * Reverse the migrations. 36 | * 37 | * @return void 38 | */ 39 | public function down() 40 | { 41 | Schema::drop('reservations'); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /database/seeds/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TwilioDevEd/airtng-laravel/6e1a5d38c3b7a6503df8209f399cb12952028107/database/seeds/.gitkeep -------------------------------------------------------------------------------- /database/seeds/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | call(ReservationSeeder::class); 18 | 19 | Model::reguard(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /database/seeds/ReservationSeeder.php: -------------------------------------------------------------------------------- 1 | 'Captain Kirk', 18 | 'email' => 'jkirk@enterprise.space', 19 | 'password' => Hash::make('strongpassword'), 20 | 'country_code' => '1', 21 | 'phone_number' => '5558180101'] 22 | ); 23 | $hostUser->save(); 24 | $guestUser = new User( 25 | ['name' => 'Mr. Spock', 26 | 'email' => 'spock@enterprise.space', 27 | 'password' => Hash::make('l1v3l0ngandpr0sp3r'), 28 | 'country_code' => '1', 29 | 'phone_number' => '5558180202'] 30 | ); 31 | $guestUser->save(); 32 | 33 | $property = new VacationProperty( 34 | ['description' => 'USS Enterprise', 35 | 'image_url' => 'http://www.ex-astris-scientia.org/articles/new_enterprise/enterprise-11-11-08.jpg'] 36 | ); 37 | $hostUser->properties()->save($property); 38 | 39 | $reservation = new Reservation( 40 | ['message' => 'I want to reserve a room in your ship'] 41 | ); 42 | $reservation->respond_phone_number = $guestUser->fullNumber(); 43 | $reservation->user()->associate($hostUser); 44 | $property->reservations()->save($reservation); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.8" 2 | services: 3 | app: 4 | restart: always 5 | build: . 6 | ports: 7 | - "8000:8000" 8 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var elixir = require('laravel-elixir'); 2 | 3 | /* 4 | |-------------------------------------------------------------------------- 5 | | Elixir Asset Management 6 | |-------------------------------------------------------------------------- 7 | | 8 | | Elixir provides a clean, fluent API for defining some basic Gulp tasks 9 | | for your Laravel application. By default, we are compiling the Sass 10 | | file for our application, as well as publishing vendor resources. 11 | | 12 | */ 13 | 14 | elixir(function(mix) { 15 | mix.sass('app.scss'); 16 | }); 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "devDependencies": { 4 | "gulp": "^3.8.8" 5 | }, 6 | "dependencies": { 7 | "laravel-elixir": "^3.0.0", 8 | "bootstrap-sass": "^3.0.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /phpspec.yml: -------------------------------------------------------------------------------- 1 | suites: 2 | main: 3 | namespace: App 4 | psr4_prefix: App 5 | src_path: app -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | ./tests/ 14 | 15 | 16 | 17 | 18 | ./app 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Redirect Trailing Slashes If Not A Folder... 9 | RewriteCond %{REQUEST_FILENAME} !-d 10 | RewriteRule ^(.*)/$ /$1 [L,R=301] 11 | 12 | # Handle Front Controller... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_FILENAME} !-f 15 | RewriteRule ^ index.php [L] 16 | 17 | -------------------------------------------------------------------------------- /public/css/application.css: -------------------------------------------------------------------------------- 1 | @import url(http://fonts.googleapis.com/css?family=Raleway:400,600,300); 2 | 3 | html { 4 | box-sizing:border-box; 5 | } 6 | 7 | body { 8 | font-family: 'Raleway', sans-serif; 9 | } 10 | 11 | *, *:before, *:after { 12 | box-sizing:inherit; 13 | } 14 | 15 | a:visited { 16 | color:black; 17 | } 18 | 19 | footer { 20 | font-size:12px; 21 | color:#787878; 22 | margin-top:20px; 23 | padding-top:20px; 24 | text-align:center; 25 | } 26 | 27 | footer i { 28 | color:#ff0000; 29 | } 30 | 31 | nav a:focus { 32 | text-decoration:none; 33 | color:#337ab7; 34 | } 35 | 36 | td { 37 | padding:10px; 38 | } 39 | 40 | #main { 41 | margin-top:10px; 42 | } 43 | 44 | #messages p { 45 | padding:10px; 46 | border:1px solid #eee; 47 | } 48 | 49 | #messages i { 50 | float:right; 51 | margin-left:5px; 52 | cursor:pointer; 53 | } 54 | 55 | #countries-input-0{ 56 | display: block; 57 | width: 100%; 58 | height: 34px; 59 | padding: 6px 12px; 60 | font-size: 14px; 61 | line-height: 1.42857; 62 | color: #555; 63 | background-color: #FFF; 64 | background-image: none; 65 | border: 1px solid #CCC; 66 | border-radius: 4px; 67 | box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.075) inset; 68 | transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s; 69 | } 70 | -------------------------------------------------------------------------------- /public/css/main.css: -------------------------------------------------------------------------------- 1 | body.cover footer { 2 | text-align: center; 3 | position: absolute; 4 | bottom: 20px; 5 | width: 100%; 6 | } 7 | 8 | .hero-text { 9 | background: url('/images/tngbg.jpg'); 10 | margin: 0px; 11 | top: 0px; 12 | text-align: center; 13 | padding: 130px; 14 | color: white; 15 | background-size: cover; 16 | } 17 | .hero-text.full-page { 18 | height: 100%; 19 | position: absolute; 20 | width: 100%; 21 | } 22 | .hero-text h1 { 23 | font-size: 60px; 24 | text-transform: uppercase; 25 | } 26 | .hero-text p { 27 | font-size: 30px; 28 | } 29 | .hero-text .btn-transparent { 30 | background: rgba(255, 255, 255, 0.6); 31 | margin: 30px; 32 | color: white; 33 | font-weight: 600; 34 | letter-spacing: 1px; 35 | } 36 | 37 | .navbar { 38 | border-radius: 0px !important; 39 | } 40 | .navbar.navbar-transparent { 41 | background: transparent; 42 | position: absolute; 43 | width: 100%; 44 | top: 0px; 45 | z-index: 1020; 46 | padding: 20px; 47 | } 48 | .navbar.navbar-space { 49 | background: url('/images/tngbg.jpg'); 50 | height: 90px; 51 | } 52 | .navbar .navbar-brand { 53 | background: url('/images/airtng-logo.png') no-repeat; 54 | padding-left: 40px; 55 | color: white; 56 | font-size: 32px; 57 | } 58 | .navbar img { 59 | width: 20px; 60 | } 61 | .navbar li { 62 | list-style: none; 63 | margin: 10px; 64 | } 65 | .navbar li a { 66 | color: #337ab7 !important; 67 | font-size: 14px; 68 | } 69 | .navbar li a:hover { 70 | background: transparent; 71 | text-decoration: none; 72 | } 73 | .navbar li a:visited { 74 | color: #337ab7 !important; 75 | } 76 | 77 | #main.push-hero { 78 | margin-top: 30px; 79 | } 80 | 81 | #main.push-nav { 82 | margin-top: 60px; 83 | } 84 | -------------------------------------------------------------------------------- /public/css/scaffolds.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #fff; 3 | color: #333; 4 | font-family: verdana, arial, helvetica, sans-serif; 5 | font-size: 13px; 6 | line-height: 18px; 7 | } 8 | 9 | p, ol, ul, td { 10 | font-family: verdana, arial, helvetica, sans-serif; 11 | font-size: 13px; 12 | line-height: 18px; 13 | } 14 | 15 | pre { 16 | background-color: #eee; 17 | padding: 10px; 18 | font-size: 11px; 19 | } 20 | 21 | a { 22 | color: #000; 23 | } 24 | a:visited { 25 | color: #666; 26 | } 27 | a:hover { 28 | color: #fff; 29 | background-color: #000; 30 | } 31 | 32 | div.field, div.actions { 33 | margin-bottom: 10px; 34 | } 35 | 36 | #notice { 37 | color: green; 38 | } 39 | 40 | .field_with_errors { 41 | padding: 2px; 42 | background-color: red; 43 | display: table; 44 | } 45 | 46 | #error_explanation { 47 | width: 450px; 48 | border: 2px solid red; 49 | padding: 7px; 50 | padding-bottom: 0; 51 | margin-bottom: 20px; 52 | background-color: #f0f0f0; 53 | } 54 | #error_explanation h2 { 55 | text-align: left; 56 | font-weight: bold; 57 | padding: 5px 5px 5px 15px; 58 | font-size: 12px; 59 | margin: -7px; 60 | margin-bottom: 0px; 61 | background-color: #c00; 62 | color: #fff; 63 | } 64 | #error_explanation ul li { 65 | font-size: 12px; 66 | list-style: square; 67 | } 68 | -------------------------------------------------------------------------------- /public/css/vacation_properties.css: -------------------------------------------------------------------------------- 1 | body.property-page footer { 2 | position: relative; 3 | } 4 | body.property-page #main { 5 | min-height: 900px; 6 | } 7 | 8 | .property { 9 | display: block; 10 | position: relative; 11 | border-radius: 10px; 12 | text-align: center; 13 | padding-top: 88px; 14 | height: 240px; 15 | text-transform: uppercase; 16 | overflow: hidden; 17 | margin-bottom: 20px; 18 | } 19 | .property img { 20 | vertical-align: middle; 21 | width: 100%; 22 | position: absolute; 23 | left: 0px; 24 | top: 0px; 25 | border-radius: 10px; 26 | } 27 | .property h2 { 28 | color: white; 29 | z-index: 1000; 30 | position: relative; 31 | } 32 | 33 | .property-detail { 34 | position: absolute; 35 | top: 0px; 36 | width: 100%; 37 | } 38 | .property-detail .overview { 39 | height: 400px; 40 | overflow: hidden; 41 | } 42 | .property-detail img { 43 | width: 100%; 44 | } 45 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TwilioDevEd/airtng-laravel/6e1a5d38c3b7a6503df8209f399cb12952028107/public/favicon.ico -------------------------------------------------------------------------------- /public/images/airtng-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TwilioDevEd/airtng-laravel/6e1a5d38c3b7a6503df8209f399cb12952028107/public/images/airtng-logo.png -------------------------------------------------------------------------------- /public/images/spock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TwilioDevEd/airtng-laravel/6e1a5d38c3b7a6503df8209f399cb12952028107/public/images/spock.png -------------------------------------------------------------------------------- /public/images/tngbg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TwilioDevEd/airtng-laravel/6e1a5d38c3b7a6503df8209f399cb12952028107/public/images/tngbg.jpg -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | /* 11 | |-------------------------------------------------------------------------- 12 | | Register The Auto Loader 13 | |-------------------------------------------------------------------------- 14 | | 15 | | Composer provides a convenient, automatically generated class loader for 16 | | our application. We just need to utilize it! We'll simply require it 17 | | into the script here so that we don't have to worry about manual 18 | | loading any of our classes later on. It feels nice to relax. 19 | | 20 | */ 21 | 22 | require __DIR__.'/../bootstrap/autoload.php'; 23 | 24 | /* 25 | |-------------------------------------------------------------------------- 26 | | Turn On The Lights 27 | |-------------------------------------------------------------------------- 28 | | 29 | | We need to illuminate PHP development, so let us turn on the lights. 30 | | This bootstraps the framework and gets it ready for use, then it 31 | | will load up this application so that we can run it and send 32 | | the responses back to the browser and delight our users. 33 | | 34 | */ 35 | 36 | $app = require_once __DIR__.'/../bootstrap/app.php'; 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Run The Application 41 | |-------------------------------------------------------------------------- 42 | | 43 | | Once we have the application, we can handle the incoming request 44 | | through the kernel, and send the associated response back to 45 | | the client's browser allowing them to enjoy the creative 46 | | and wonderful application we have prepared for them. 47 | | 48 | */ 49 | 50 | $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); 51 | 52 | $response = $kernel->handle( 53 | $request = Illuminate\Http\Request::capture() 54 | ); 55 | 56 | $response->send(); 57 | 58 | $kernel->terminate($request, $response); 59 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | 2 | Twilio 3 | 4 | 5 | # Airtng App: Part 1 - Workflow Automation with Twilio - Laravel 6 | 7 | ![](https://github.com/TwilioDevEd/airtng-laravel/workflows/Laravel/badge.svg) 8 | 9 | > We are currently in the process of updating this sample template. If you are encountering any issues with the sample, please open an issue at [github.com/twilio-labs/code-exchange/issues](https://github.com/twilio-labs/code-exchange/issues) and we'll try to help you. 10 | 11 | ## About 12 | 13 | Learn how to automate your workflow using Twilio's REST API and Twilio SMS. This example app is a vacation rental site where the host can confirm a reservation via SMS. 14 | 15 | [Read the full tutorial here](https://www.twilio.com/docs/tutorials/walkthrough/workflow-automation/php/laravel)! 16 | 17 | Implementations in other languages: 18 | 19 | | .NET | Java | Python | Ruby | Node | 20 | | :--- | :--- | :----- | :-- | :--- | 21 | | [Done](https://github.com/TwilioDevEd/airtng-csharp-dotnet-core) | [Done](https://github.com/TwilioDevEd/airtng-servlets) | [Done](https://github.com/TwilioDevEd/airtng-flask) | TBD | [Done](https://github.com/TwilioDevEd/airtng-node) | 22 | 23 | ## Set up 24 | 25 | ### Requirements 26 | 27 | - [PHP >= 7.2.5](https://www.php.net/) and [composer](https://getcomposer.org/) 28 | - A Twilio account - [sign up](https://www.twilio.com/try-twilio) 29 | - The application uses [sqlite3](https://www.sqlite.org/) as the persistence layer. If you don't have it already, you should install it. 30 | 31 | ### Twilio Account Settings 32 | 33 | This application should give you a ready-made starting point for writing your own application. 34 | Before we begin, we need to collect all the config values we need to run the application: 35 | 36 | | Config Value | Description | 37 | | :---------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------- | 38 | | Account Sid | Your primary Twilio account identifier - find this [in the Console](https://www.twilio.com/console). | 39 | | Auth Token | Used to authenticate - [just like the above, you'll find this here](https://www.twilio.com/console). | 40 | | Phone number | A Twilio phone number in [E.164 format](https://en.wikipedia.org/wiki/E.164) - you can [get one here](https://www.twilio.com/console/phone-numbers/incoming) | 41 | 42 | ### Local development 43 | 44 | After the above requirements have been met: 45 | 46 | 1. Clone this repository and `cd` into it 47 | 48 | ```bash 49 | git clone git@github.com:TwilioDevEd/airtng-laravel.git 50 | cd airtng-laravel 51 | ``` 52 | 53 | 1. Set your environment variables 54 | 55 | ```bash 56 | cp .env.example .env 57 | ``` 58 | 59 | See [Twilio Account Settings](#twilio-account-settings) to locate the necessary environment variables. 60 | 61 | 1. Install PHP dependencies 62 | 63 | ```bash 64 | make install 65 | ``` 66 | 67 | 1. Expose the application to the wider Internet using [ngrok](https://ngrok.com/) 68 | 69 | ```bash 70 | $ ngrok http 8000 71 | ``` 72 | 73 | Once you have started ngrok, update your Twilio number sms URL settings to use your ngrok hostname. It will look something like this: 74 | 75 | ``` 76 | http://.ngrok.io/reservation/incoming 77 | ``` 78 | 79 | 6. Configure Twilio to call your webhooks. 80 | 81 | You will also need to configure Twilio to send requests to your application when sms are received. 82 | 83 | You will need to provision at least one Twilio number with sms capabilities so the application's users can make property reservations. You can buy a number [right here](https://www.twilio.com/user/account/phone-numbers/search). Once you have a number you need to configure it to work with your application. Open [the number management page](https://www.twilio.com/user/account/phone-numbers/incoming) and open a number's configuration by clicking on it. 84 | 85 | Remember that the number where you change the sms webhooks must be the same one you set on the `TWILIO_NUMBER` environment variable. 86 | 87 | ![Configure Messaging](webhook.png) 88 | 89 | For this application, you must set the voice webhook of your number so that it looks something like this: 90 | 91 | ``` 92 | http://.ngrok.io/reservation/incoming 93 | ``` 94 | 95 | And in this case set the `POST` method on the configuration for this webhook. 96 | 97 | 1. Run the application 98 | 99 | ```bash 100 | make serve 101 | ``` 102 | 103 | 1. Navigate to [http://localhost:8000](http://localhost:8000) 104 | 105 | That's it! 106 | 107 | ### Docker 108 | 109 | If you have [Docker](https://www.docker.com/) already installed on your machine, you can use our `docker-compose.yml` to setup your project. 110 | 111 | 1. Make sure you have the project cloned. 112 | 2. Setup the `.env` file as outlined in the [Local Development](#local-development) steps. 113 | 3. Run `docker-compose up`. 114 | 4. Follow the steps in [Local Development](#local-development) on how to expose your port to Twilio using a tool like [ngrok](https://ngrok.com/) and configure the remaining parts of your application. 115 | 116 | ### Unit and Integration Tests 117 | 118 | First, run the migrations for the testing database. 119 | ```bash 120 | php artisan migrate --database=testing 121 | ``` 122 | 123 | You can run the Unit tests locally by typing: 124 | ```bash 125 | vendor/bin/phpunit 126 | ``` 127 | 128 | ### Cloud deployment 129 | 130 | Additionally to trying out this application locally, you can deploy it to a variety of host services. Here is a small selection of them. 131 | 132 | Please be aware that some of these might charge you for the usage or might make the source code for this application visible to the public. When in doubt research the respective hosting service first. 133 | 134 | | Service | | 135 | | :-------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | 136 | | [Heroku](https://www.heroku.com/) | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) | 137 | 138 | ## Resources 139 | 140 | - The CodeExchange repository can be found [here](https://github.com/twilio-labs/code-exchange/). 141 | 142 | ## Contributing 143 | 144 | This template is open source and welcomes contributions. All contributions are subject to our [Code of Conduct](https://github.com/twilio-labs/.github/blob/master/CODE_OF_CONDUCT.md). 145 | 146 | ## License 147 | 148 | [MIT](http://www.opensource.org/licenses/mit-license.html) 149 | 150 | ## Disclaimer 151 | 152 | No warranty expressed or implied. Software is as is. 153 | 154 | [twilio]: https://www.twilio.com 155 | -------------------------------------------------------------------------------- /resources/assets/sass/app.scss: -------------------------------------------------------------------------------- 1 | // @import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap"; 2 | 3 | -------------------------------------------------------------------------------- /resources/lang/en/auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 17 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/pagination.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 'next' => 'Next »', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/passwords.php: -------------------------------------------------------------------------------- 1 | 'Passwords must be at least six characters and match the confirmation.', 17 | 'reset' => 'Your password has been reset!', 18 | 'sent' => 'We have e-mailed your password reset link!', 19 | 'token' => 'This password reset token is invalid.', 20 | 'user' => "We can't find a user with that e-mail address.", 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /resources/lang/en/validation.php: -------------------------------------------------------------------------------- 1 | 'The :attribute must be accepted.', 17 | 'active_url' => 'The :attribute is not a valid URL.', 18 | 'after' => 'The :attribute must be a date after :date.', 19 | 'alpha' => 'The :attribute may only contain letters.', 20 | 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', 21 | 'alpha_num' => 'The :attribute may only contain letters and numbers.', 22 | 'array' => 'The :attribute must be an array.', 23 | 'before' => 'The :attribute must be a date before :date.', 24 | 'between' => [ 25 | 'numeric' => 'The :attribute must be between :min and :max.', 26 | 'file' => 'The :attribute must be between :min and :max kilobytes.', 27 | 'string' => 'The :attribute must be between :min and :max characters.', 28 | 'array' => 'The :attribute must have between :min and :max items.', 29 | ], 30 | 'boolean' => 'The :attribute field must be true or false.', 31 | 'confirmed' => 'The :attribute confirmation does not match.', 32 | 'date' => 'The :attribute is not a valid date.', 33 | 'date_format' => 'The :attribute does not match the format :format.', 34 | 'different' => 'The :attribute and :other must be different.', 35 | 'digits' => 'The :attribute must be :digits digits.', 36 | 'digits_between' => 'The :attribute must be between :min and :max digits.', 37 | 'email' => 'The :attribute must be a valid email address.', 38 | 'exists' => 'The selected :attribute is invalid.', 39 | 'filled' => 'The :attribute field is required.', 40 | 'image' => 'The :attribute must be an image.', 41 | 'in' => 'The selected :attribute is invalid.', 42 | 'integer' => 'The :attribute must be an integer.', 43 | 'ip' => 'The :attribute must be a valid IP address.', 44 | 'json' => 'The :attribute must be a valid JSON string.', 45 | 'max' => [ 46 | 'numeric' => 'The :attribute may not be greater than :max.', 47 | 'file' => 'The :attribute may not be greater than :max kilobytes.', 48 | 'string' => 'The :attribute may not be greater than :max characters.', 49 | 'array' => 'The :attribute may not have more than :max items.', 50 | ], 51 | 'mimes' => 'The :attribute must be a file of type: :values.', 52 | 'min' => [ 53 | 'numeric' => 'The :attribute must be at least :min.', 54 | 'file' => 'The :attribute must be at least :min kilobytes.', 55 | 'string' => 'The :attribute must be at least :min characters.', 56 | 'array' => 'The :attribute must have at least :min items.', 57 | ], 58 | 'not_in' => 'The selected :attribute is invalid.', 59 | 'numeric' => 'The :attribute must be a number.', 60 | 'regex' => 'The :attribute format is invalid.', 61 | 'required' => 'The :attribute field is required.', 62 | 'required_if' => 'The :attribute field is required when :other is :value.', 63 | 'required_with' => 'The :attribute field is required when :values is present.', 64 | 'required_with_all' => 'The :attribute field is required when :values is present.', 65 | 'required_without' => 'The :attribute field is required when :values is not present.', 66 | 'required_without_all' => 'The :attribute field is required when none of :values are present.', 67 | 'same' => 'The :attribute and :other must match.', 68 | 'size' => [ 69 | 'numeric' => 'The :attribute must be :size.', 70 | 'file' => 'The :attribute must be :size kilobytes.', 71 | 'string' => 'The :attribute must be :size characters.', 72 | 'array' => 'The :attribute must contain :size items.', 73 | ], 74 | 'string' => 'The :attribute must be a string.', 75 | 'timezone' => 'The :attribute must be a valid zone.', 76 | 'unique' => 'The :attribute has already been taken.', 77 | 'url' => 'The :attribute format is invalid.', 78 | 79 | /* 80 | |-------------------------------------------------------------------------- 81 | | Custom Validation Language Lines 82 | |-------------------------------------------------------------------------- 83 | | 84 | | Here you may specify custom validation messages for attributes using the 85 | | convention "attribute.rule" to name the lines. This makes it quick to 86 | | specify a specific custom language line for a given attribute rule. 87 | | 88 | */ 89 | 90 | 'custom' => [ 91 | 'attribute-name' => [ 92 | 'rule-name' => 'custom-message', 93 | ], 94 | ], 95 | 96 | /* 97 | |-------------------------------------------------------------------------- 98 | | Custom Validation Attributes 99 | |-------------------------------------------------------------------------- 100 | | 101 | | The following language lines are used to swap attribute place-holders 102 | | with something more reader friendly such as E-Mail Address instead 103 | | of "email". This simply helps us make messages a little cleaner. 104 | | 105 | */ 106 | 107 | 'attributes' => [], 108 | 109 | ]; 110 | -------------------------------------------------------------------------------- /resources/views/_messages.blade.php: -------------------------------------------------------------------------------- 1 | @if (count($errors) > 0) 2 | 8 | @endif 9 | 10 | @if (session('status') !== null) 11 | 15 | @endif 16 | -------------------------------------------------------------------------------- /resources/views/errors/503.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Be right back. 5 | 6 | 7 | 8 | 39 | 40 | 41 |
42 |
43 |
Be right back.
44 |
45 |
46 | 47 | 48 | -------------------------------------------------------------------------------- /resources/views/home.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.master') 2 | 3 | @section('title') 4 | Home 5 | @endsection 6 | 7 | @section('body_class') 8 | "cover" 9 | @endsection 10 | 11 | @section('hero') 12 |
13 |

Lodging fit for a captain

14 |

The Next Generation of vacation rentals.

15 | 16 | View Properties 17 |
18 | @endsection 19 | -------------------------------------------------------------------------------- /resources/views/layouts/master.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {!! csrf_field() !!} 6 | @yield('title') - Workflow Automation 7 | 8 | 9 | 11 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | @yield('css') 21 | 22 | 23 | @yield('nav_bg') 24 | 25 | 39 | 40 | @yield('hero') 41 |
42 | @include('_messages') 43 | @yield('content') 44 |
45 | 46 |
47 | Made with by your pals 48 | @twilio 49 |
50 | 51 | 52 | 53 | 54 | 55 | @yield('javascript') 56 | 57 | 58 | -------------------------------------------------------------------------------- /resources/views/login.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.master') 2 | 3 | @section('title') 4 | Log in 5 | @endsection 6 | 7 | @section('nav_bg') 8 | 9 | 11 | @endsection 12 | 13 | @section('content') 14 |
15 | 29 |
30 | @endsection 31 | -------------------------------------------------------------------------------- /resources/views/newUser.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.master') 2 | 3 | @section('title') 4 | Sign Up 5 | @endsection 6 | 7 | @section('nav_bg') 8 | 9 | 11 | @endsection 12 | 13 | @section('content') 14 |
15 |

Sign up for Airtng

16 | 17 | {!! Form::open(['url' => route('user-create')]) !!} 18 |
19 | {!! Form::label('name') !!} 20 | {!! Form::text('name', '', ['class' => 'form-control', 'placeholder' => 'Zingelbert Bembledack']) !!} 21 |
22 |
23 | {!! Form::label('email') !!} 24 | {!! Form::text('email', '', ['class' => 'form-control', 'placeholder' => 'me@mydomain.com']) !!} 25 |
26 |
27 | {!! Form::label('password') !!} 28 | {!! Form::password('password', ['class' => 'form-control']) !!} 29 |
30 |
31 | {!! Form::label('country_code', 'Country Code') !!} 32 | {!! Form::text('country_code', '', ['class' => 'form-control', 'id' => 'authy-countries']) !!} 33 |
34 |
35 | {!! Form::label('phone_number', 'Phone number') !!} 36 | {!! Form::text('phone_number', '', ['class' => 'form-control', 'id' => 'authy-cellphone']) !!} 37 |
38 |
39 | 40 |
41 | {!! Form::close() !!} 42 |
43 | @endsection 44 | -------------------------------------------------------------------------------- /resources/views/property/_propertyForm.blade.php: -------------------------------------------------------------------------------- 1 |
2 | @if(isset($property)) 3 | {!! Form::model($property, ['url' => route('property-edit-action', ['id' => $property->id])]) !!} 4 | @else 5 | {!! Form::open(['url' => route('property-create')]) !!} 6 | @endif 7 |
8 | {!! Form::label('description') !!} 9 | {!! Form::text('description', null, ['class' => 'form-control']) !!} 10 |
11 |
12 | {!! Form::label('image_url') !!} 13 | {!! Form::text('image_url', null, ['class' => 'form-control']) !!} 14 |
15 |
16 | 23 |
24 | {!! Form::close() !!} 25 |
26 | -------------------------------------------------------------------------------- /resources/views/property/edit.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.master') 2 | 3 | @section('title') 4 | Edit Vacation Property 5 | @endsection 6 | 7 | @section('nav_bg') 8 | 9 | 11 | @endsection 12 | 13 | @section('content') 14 |
15 |

Editing Vacation Property

16 | @include('property._propertyForm') 17 | 18 | Back to properties 19 |
20 | @endsection 21 | -------------------------------------------------------------------------------- /resources/views/property/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.master') 2 | 3 | @section('title') 4 | Properties 5 | @endsection 6 | 7 | @section('hero') 8 |
9 |

Lodging fit for a captain

10 |

The Next Generation of vacation rentals.

11 |
12 | @endsection 13 | 14 | @section('content') 15 |
16 |
17 | @foreach ($properties as $property) 18 | 25 | @endforeach 26 |
27 |
28 | @endsection 29 | -------------------------------------------------------------------------------- /resources/views/property/newProperty.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.master') 2 | 3 | @section('title') 4 | New Vacation Property 5 | @endsection 6 | 7 | @section('nav_bg') 8 | 9 | 11 | @endsection 12 | 13 | @section('content') 14 |
15 |

New Vacation Property

16 | @include('property._propertyForm') 17 | 18 | Back to properties 19 |
20 | @endsection 21 | -------------------------------------------------------------------------------- /resources/views/property/show.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.master') 2 | 3 | @section('title') 4 | Home 5 | @endsection 6 | 7 | @section('body_class') 8 | "property-page" 9 | @endsection 10 | 11 | @section('content') 12 |
13 |
14 | 15 |
16 |
17 | @include('_messages') 18 |

{{ $property->description }}

Edit 19 |
20 |
21 |
22 |

Make a Reservation

23 |
24 |
25 | {!! Form::open(['url' => route('reservation-create', ['id' => $property->id])]) !!} 26 |
27 | {!! Form::label('message') !!} 28 | {!! Form::text('message', '', ['class' => 'form-control', 'placeholder' => 'Hello! I am hoping to stay in your intergalactic suite...']) !!} 29 |
30 |
31 | {!! Form::text('property_id', $property->id, ['class' => 'hidden']) !!} 32 |
33 |
34 | 35 |
36 | {!! Form::close() !!} 37 |
38 |
39 |
40 |
41 | @endsection 42 | -------------------------------------------------------------------------------- /resources/views/vendor/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TwilioDevEd/airtng-laravel/6e1a5d38c3b7a6503df8209f399cb12952028107/resources/views/vendor/.gitkeep -------------------------------------------------------------------------------- /routes/api.php: -------------------------------------------------------------------------------- 1 | id === (int) $id; 16 | }); 17 | -------------------------------------------------------------------------------- /routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 18 | })->describe('Display an inspiring quote'); 19 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | 'home', function () { 16 | return response()->view('home'); 17 | }] 18 | ); 19 | 20 | // Session related routes 21 | Route::get( 22 | '/auth/login', 23 | ['as' => 'login-index', function () { 24 | return response()->view('login'); 25 | }] 26 | ); 27 | 28 | Route::get( 29 | '/login', 30 | ['as' => 'login-index', function () { 31 | return response()->view('login'); 32 | }] 33 | ); 34 | 35 | Route::post( 36 | '/login', 37 | ['uses' => 'SessionController@login', 'as' => 'login-action'] 38 | ); 39 | 40 | Route::get( 41 | '/logout', 42 | ['as' => 'logout', function () { 43 | Auth::logout(); 44 | return redirect()->route('home'); 45 | }] 46 | ); 47 | 48 | // User related routes 49 | Route::get( 50 | '/user/new', 51 | ['as' => 'user-new', function () { 52 | return response()->view('newUser'); 53 | }] 54 | ); 55 | 56 | Route::post( 57 | '/user/create', 58 | ['uses' => 'UserController@createNewUser', 'as' => 'user-create', ] 59 | ); 60 | 61 | // Vacation Property related routes 62 | Route::get( 63 | '/property/new', 64 | ['as' => 'property-new', 65 | 'middleware' => 'auth', 66 | function () { 67 | return response()->view('property.newProperty'); 68 | }] 69 | ); 70 | 71 | Route::get( 72 | '/properties', 73 | ['as' => 'property-index', 74 | 'middleware' => 'auth', 75 | 'uses' => 'VacationPropertyController@index'] 76 | ); 77 | 78 | Route::get( 79 | '/property/{id}', 80 | ['as' => 'property-show', 81 | 'middleware' => 'auth', 82 | 'uses' => 'VacationPropertyController@show'] 83 | ); 84 | 85 | Route::get( 86 | '/property/{id}/edit', 87 | ['as' => 'property-edit', 88 | 'middleware' => 'auth', 89 | 'uses' => 'VacationPropertyController@editForm'] 90 | ); 91 | 92 | Route::post( 93 | '/property/edit/{id}', 94 | ['uses' => 'VacationPropertyController@editProperty', 95 | 'middleware' => 'auth', 96 | 'as' => 'property-edit-action'] 97 | ); 98 | 99 | Route::post( 100 | '/property/create', 101 | ['uses' => 'VacationPropertyController@createNewProperty', 102 | 'middleware' => 'auth', 103 | 'as' => 'property-create'] 104 | ); 105 | 106 | // Reservation related routes 107 | Route::post( 108 | '/property/{id}/reservation/create', 109 | ['uses' => 'ReservationController@create', 110 | 'as' => 'reservation-create', 111 | 'middleware' => 'auth'] 112 | ); 113 | 114 | Route::post( 115 | '/reservation/incoming', 116 | ['uses' => 'ReservationController@acceptReject', 117 | 'as' => 'reservation-incoming'] 118 | ); 119 | -------------------------------------------------------------------------------- /server.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | $uri = urldecode( 11 | parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) 12 | ); 13 | 14 | // This file allows us to emulate Apache's "mod_rewrite" functionality from the 15 | // built-in PHP web server. This provides a convenient way to test a Laravel 16 | // application without having installed a "real" web server software here. 17 | if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { 18 | return false; 19 | } 20 | 21 | require_once __DIR__.'/public/index.php'; 22 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /storage/framework/.gitignore: -------------------------------------------------------------------------------- 1 | config.php 2 | routes.php 3 | compiled.php 4 | services.json 5 | events.scanned.php 6 | routes.scanned.php 7 | down 8 | -------------------------------------------------------------------------------- /storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tests/ReservationControllerTest.php: -------------------------------------------------------------------------------- 1 | startSession(); 21 | $userData = [ 22 | 'name' => 'Captain Kirk', 23 | 'email' => 'jkirk@enterprise.space', 24 | 'password' => 'strongpassword', 25 | 'country_code' => '1', 26 | 'phone_number' => '5558180101' 27 | ]; 28 | 29 | $newUser = new User($userData); 30 | $newUser->save(); 31 | $this->be($newUser); 32 | 33 | $propertyData = [ 34 | 'description' => 'Some description', 35 | 'image_url' => 'http://www.someimage.com' 36 | ]; 37 | $newProperty = new VacationProperty($propertyData); 38 | $newUser->properties()->save($newProperty); 39 | $this->assertCount(0, Reservation::all()); 40 | 41 | $mockTwilioClient = Mockery::mock(Client::class) 42 | ->makePartial(); 43 | $mockTwilioMessages = Mockery::mock(); 44 | 45 | $mockTwilioClient->messages = $mockTwilioMessages; 46 | 47 | $twilioNumber = config('services.twilio')['number']; 48 | $mockTwilioMessages 49 | ->shouldReceive('create') 50 | ->with( 51 | $newUser->fullNumber(), 52 | [ 53 | 'from' => $twilioNumber, 54 | 'body' => 'Some reservation message - Reply \'yes\' or \'accept\' to confirm the reservation, or anything else to reject it.' 55 | ] 56 | ) 57 | ->once(); 58 | 59 | $this->app->instance( 60 | Client::class, 61 | $mockTwilioClient 62 | ); 63 | 64 | // When 65 | $response = $this->call( 66 | 'POST', 67 | route('reservation-create', ['id' => $newProperty->id]), 68 | ['message' => 'Some reservation message', 69 | '_token' => csrf_token()] 70 | ); 71 | 72 | // Then 73 | $this->assertCount(1, Reservation::all()); 74 | $reservation = Reservation::first(); 75 | $this->assertEquals($reservation->message, 'Some reservation message'); 76 | $response->assertRedirect(route('property-show', ['id' => $newProperty->id])); 77 | $response->assertSessionHas('status'); 78 | $flashreservation = $this->app['session']->get('status'); 79 | $this->assertEquals( 80 | $flashreservation, 81 | "Sending your reservation request now." 82 | ); 83 | } 84 | 85 | public function testAcceptRejectConfirm() 86 | { 87 | // Given 88 | $this->startSession(); 89 | $userData = [ 90 | 'name' => 'Captain Kirk host', 91 | 'email' => 'jkirkh@enterprise.space', 92 | 'password' => 'strongpassword', 93 | 'country_code' => '1', 94 | 'phone_number' => '5558180101' 95 | ]; 96 | 97 | $newUser = new User($userData); 98 | $newUser->save(); 99 | 100 | $userData2 = [ 101 | 'name' => 'Captain Kirk rent', 102 | 'email' => 'jkirkr@enterprise.space', 103 | 'password' => 'strongpassword', 104 | 'country_code' => '1', 105 | 'phone_number' => '5558180102' 106 | ]; 107 | 108 | $newUser2 = new User($userData2); 109 | $newUser2->save(); 110 | 111 | $propertyData = [ 112 | 'description' => 'Some description', 113 | 'image_url' => 'http://www.someimage.com' 114 | ]; 115 | $newProperty = new VacationProperty($propertyData); 116 | $newUser->properties()->save($newProperty); 117 | 118 | $reservationData = [ 119 | 'message' => 'Reservation message' 120 | ]; 121 | 122 | $reservation = new Reservation($reservationData); 123 | $reservation->respond_phone_number = $newUser2->fullNumber(); 124 | $reservation->user()->associate($newUser); 125 | $newProperty->reservations()->save($reservation); 126 | $reservation = $reservation->fresh(); 127 | $this->assertEquals('pending', $reservation->status); 128 | 129 | // When 130 | $response = $this->call( 131 | 'POST', 132 | route('reservation-incoming'), 133 | ['From' => '+15558180101', 134 | 'Body' => 'accept'] 135 | ); 136 | 137 | $messageDocument = new SimpleXMLElement($response->getContent()); 138 | 139 | $reservation = $reservation->fresh(); 140 | $this->assertEquals('confirmed', $reservation->status); 141 | $this->assertEquals($response->getStatusCode(), 200); 142 | $this->assertNotNull(strval($messageDocument->Message[0])); 143 | $this->assertNotEmpty(strval($messageDocument->Message[0])); 144 | $this->assertEquals(strval($messageDocument->Message[0]), 'You have successfully confirmed the reservation.'); 145 | $this->assertNotNull(strval($messageDocument->Message[1])); 146 | $this->assertNotEmpty(strval($messageDocument->Message[1])); 147 | $this->assertEquals(strval($messageDocument->Message[1]), 'Your reservation has been confirmed.'); 148 | $this->assertEquals(strval($messageDocument->Message[1]->attributes()[0]), '+15558180102'); 149 | } 150 | 151 | public function testAcceptRejectReject() 152 | { 153 | // Given 154 | $this->startSession(); 155 | $userData = [ 156 | 'name' => 'Captain Kirk', 157 | 'email' => 'jkirk@enterprise.space', 158 | 'password' => 'strongpassword', 159 | 'country_code' => '1', 160 | 'phone_number' => '5558180101' 161 | ]; 162 | 163 | $newUser = new User($userData); 164 | $newUser->save(); 165 | 166 | $userData2 = [ 167 | 'name' => 'Captain Kirk rent', 168 | 'email' => 'jkirkr@enterprise.space', 169 | 'password' => 'strongpassword', 170 | 'country_code' => '1', 171 | 'phone_number' => '5558180102' 172 | ]; 173 | 174 | $newUser2 = new User($userData2); 175 | $newUser2->save(); 176 | 177 | $propertyData = [ 178 | 'description' => 'Some description', 179 | 'image_url' => 'http://www.someimage.com' 180 | ]; 181 | $newProperty = new VacationProperty($propertyData); 182 | $newUser->properties()->save($newProperty); 183 | 184 | $reservationData = [ 185 | 'message' => 'Reservation message' 186 | ]; 187 | 188 | $reservation = new Reservation($reservationData); 189 | $reservation->respond_phone_number = $newUser2->fullNumber(); 190 | $reservation->user()->associate($newUser); 191 | $newProperty->reservations()->save($reservation); 192 | $reservation = $reservation->fresh(); 193 | $this->assertEquals('pending', $reservation->status); 194 | 195 | // When 196 | $response = $this->call( 197 | 'POST', 198 | route('reservation-incoming'), 199 | ['From' => '+15558180101', 200 | 'Body' => 'any other string'] 201 | ); 202 | $messageDocument = new SimpleXMLElement($response->getContent()); 203 | 204 | $reservation = $reservation->fresh(); 205 | $this->assertEquals('rejected', $reservation->status); 206 | $this->assertEquals($response->getStatusCode(), 200); 207 | $this->assertNotNull(strval($messageDocument->Message[0])); 208 | $this->assertNotEmpty(strval($messageDocument->Message[0])); 209 | $this->assertEquals(strval($messageDocument->Message[0]), 'You have successfully rejected the reservation.'); 210 | $this->assertNotNull(strval($messageDocument->Message[1])); 211 | $this->assertNotEmpty(strval($messageDocument->Message[1])); 212 | $this->assertEquals(strval($messageDocument->Message[1]), 'Your reservation has been rejected.'); 213 | $this->assertEquals(strval($messageDocument->Message[1]->attributes()[0]), '+15558180102'); 214 | } 215 | 216 | public function testAcceptRejectNoPending() 217 | { 218 | // Given 219 | $this->startSession(); 220 | $userData = [ 221 | 'name' => 'Captain Kirk', 222 | 'email' => 'jkirk@enterprise.space', 223 | 'password' => 'strongpassword', 224 | 'country_code' => '1', 225 | 'phone_number' => '5558180101' 226 | ]; 227 | 228 | $newUser = new User($userData); 229 | $newUser->save(); 230 | 231 | $userData2 = [ 232 | 'name' => 'Captain Kirk rent', 233 | 'email' => 'jkirkr@enterprise.space', 234 | 'password' => 'strongpassword', 235 | 'country_code' => '1', 236 | 'phone_number' => '5558180102' 237 | ]; 238 | 239 | $newUser2 = new User($userData2); 240 | $newUser2->save(); 241 | 242 | $propertyData = [ 243 | 'description' => 'Some description', 244 | 'image_url' => 'http://www.someimage.com' 245 | ]; 246 | $newProperty = new VacationProperty($propertyData); 247 | $newUser->properties()->save($newProperty); 248 | 249 | $reservationData = [ 250 | 'message' => 'Reservation message' 251 | ]; 252 | 253 | $reservation = new Reservation($reservationData); 254 | $reservation->status = 'confirmed'; 255 | $reservation->respond_phone_number = $newUser2->fullNumber(); 256 | $reservation->user()->associate($newUser); 257 | $newProperty->reservations()->save($reservation); 258 | $reservation = $reservation->fresh(); 259 | $this->assertEquals('confirmed', $reservation->status); 260 | 261 | // When 262 | $response = $this->call( 263 | 'POST', 264 | route('reservation-incoming'), 265 | ['From' => '+15558180101', 266 | 'Body' => 'yes'] 267 | ); 268 | $messageDocument = new SimpleXMLElement($response->getContent()); 269 | 270 | $reservation = $reservation->fresh(); 271 | $this->assertEquals('confirmed', $reservation->status); 272 | $this->assertEquals($response->getStatusCode(), 200); 273 | $this->assertNotNull(strval($messageDocument->Message[0])); 274 | $this->assertNotEmpty(strval($messageDocument->Message[0])); 275 | $this->assertEquals(strval($messageDocument->Message[0]), 'Sorry, it looks like you don\'t have any reservations to respond to.'); 276 | } 277 | } 278 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class)->bootstrap(); 28 | 29 | return $app; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/UserControllerTest.php: -------------------------------------------------------------------------------- 1 | startSession(); 16 | $validName = 'Captain Kirk'; 17 | $validEmail = 'jkirk@enterprise.space'; 18 | $validPassword = 'strongpassword'; 19 | $validCountryCode = '1'; 20 | $validPhoneNumber = '5558180101'; 21 | $this->assertCount(0, User::all()); 22 | 23 | // When 24 | $response = $this->call( 25 | 'POST', 26 | route('user-create'), 27 | ['name' => $validName, 28 | 'email' => $validEmail, 29 | 'password' => $validPassword, 30 | 'country_code' => $validCountryCode, 31 | 'phone_number' => $validPhoneNumber, 32 | '_token' => csrf_token()] 33 | ); 34 | 35 | // Then 36 | $this->assertCount(1, User::all()); 37 | $user = User::first(); 38 | $this->assertEquals($user->name, $validName); 39 | $this->assertEquals($user->email, $validEmail); 40 | $this->assertEquals($user->country_code, $validCountryCode); 41 | $this->assertEquals($user->phone_number, $validPhoneNumber); 42 | $response->assertRedirect(route('home')); 43 | $response->assertSessionHas('status'); 44 | $flashMessage = $this->app['session']->get('status'); 45 | $this->assertEquals( 46 | $flashMessage, 47 | "User created successfully" 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/VacationPropertyControllerTest.php: -------------------------------------------------------------------------------- 1 | startSession(); 17 | $userData = [ 18 | 'name' => 'Captain Kirk', 19 | 'email' => 'jkirk@enterprise.space', 20 | 'password' => 'strongpassword', 21 | 'country_code' => '1', 22 | 'phone_number' => '5558180101' 23 | ]; 24 | 25 | $newUser = new User($userData); 26 | $newUser->save(); 27 | $this->be($newUser); 28 | 29 | $validDescription = 'Some description'; 30 | $validImageUrl = 'http://www.someimage.com'; 31 | $this->assertCount(0, VacationProperty::all()); 32 | 33 | // When 34 | $response = $this->call( 35 | 'POST', 36 | route('property-create'), 37 | ['description' => $validDescription, 38 | 'image_url' => $validImageUrl, 39 | '_token' => csrf_token()] 40 | ); 41 | 42 | // Then 43 | $this->assertCount(1, VacationProperty::all()); 44 | $property = VacationProperty::first(); 45 | $this->assertEquals($property->description, $validDescription); 46 | $this->assertEquals($property->image_url, $validImageUrl); 47 | $response->assertRedirect(route('property-index')); 48 | $response->assertSessionHas('status'); 49 | $flashMessage = $this->app['session']->get('status'); 50 | $this->assertEquals( 51 | $flashMessage, 52 | "Property successfully created" 53 | ); 54 | } 55 | 56 | function testEditProperty() { 57 | // Given 58 | $this->startSession(); 59 | $userData = [ 60 | 'name' => 'Captain Kirk', 61 | 'email' => 'jkirk@enterprise.space', 62 | 'password' => 'strongpassword', 63 | 'country_code' => '1', 64 | 'phone_number' => '5558180101' 65 | ]; 66 | 67 | $newUser = new User($userData); 68 | $newUser->save(); 69 | $this->be($newUser); 70 | 71 | $propertyData = [ 72 | 'description' => 'Some description', 73 | 'image_url' => 'http://www.someimage.com' 74 | ]; 75 | $newProperty = new VacationProperty($propertyData); 76 | $newUser->properties()->save($newProperty); 77 | $this->assertCount(1, VacationProperty::all()); 78 | 79 | // When 80 | $response = $this->call( 81 | 'POST', 82 | route('property-edit-action', ['id' => $newProperty->id]), 83 | ['description' => 'edited description', 84 | 'image_url' => 'http://www.modified.net', 85 | '_token' => csrf_token()] 86 | ); 87 | 88 | // Then 89 | $this->assertCount(1, VacationProperty::all()); 90 | $property = VacationProperty::first(); 91 | $this->assertEquals($property->description, 'edited description'); 92 | $this->assertEquals($property->image_url, 'http://www.modified.net'); 93 | $response->assertRedirect(route('property-show', ['id' => $property->id])); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /webhook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TwilioDevEd/airtng-laravel/6e1a5d38c3b7a6503df8209f399cb12952028107/webhook.png --------------------------------------------------------------------------------