How to Setup Database in Laravel Vapor?

By Hardik Savani July 5, 2021 Category : Laravel

This simple article demonstrates of laravel vapor database example. if you have question about configure database in laravel vapor then i will give simple example with solution. we will help you to give example of how to setup database in laravel vapor. We will look at example of laravel vapor database example.

In this post i will give you simple example of how to configure database with laravel vapor. we will install laravel ui package and make auth system. then we will create database on vapor and run migration and see simple authentication.

My previous post about How to Deploy Project with Laravel Vapor? from here we will proceed step by step.

Step 1: Install Laravel ui

In this step we will install laravel ui composer package. so let's run bellow command:

composer require laravel/ui

Step 2: Generate Auth Scaffolding

After installing laravel ui, we need to generate auth scaffolding using bellow command. then we will install npm and migration.

php artisan ui bootstrap --auth

after that install npm command:

npm install && npm run dev

after that run migration command:

php artisan migrate

Step 3: Create Database to Vapor

after done locally, we need to create database on vapor. on left side there is a option call database and click on it. where you can manage all database. you can also create from there as bellow:

Step 4: Setup Database Locally and Deploy

now we need to use that database on vapor.yml file and deploy project. so let's add vapor database name here and deploy it.

vapor.yml

id: 22442

name: itsolutionstuff-vapor

environments:

production:

memory: 1024

cli-memory: 512

runtime: 'php-8.0:al2'

build:

- 'COMPOSER_MIRROR_PATH_REPOS=1 composer install --no-dev'

staging:

memory: 1024

cli-memory: 512

runtime: 'php-8.0:al2'

database: itsolutionstuff-vapor-staging

deploy:

- 'php artisan migrate --force'

build:

- 'COMPOSER_MIRROR_PATH_REPOS=1 composer install'

now just deploy it.

php vendor/bin/vapor deploy

now you can open staging url as bellow:

https://frosty-forest-e7rbjvmbyo40.vapor-farm-a1.com/

you will can register and login:

You can also Run Migration on Vapor

we need to run migration on vapor command. so let's go on vapor staging command tab:

Click on Run command and add migration command there:

After run command, you will see layout as bellow:

i hope it can help you...

Tags :