feat(quickstarts): Laravel and Rails. (#20264)

* feat(quickstarts): Laravel and Rails.

* Apply suggestions from code review

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>

---------

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>
This commit is contained in:
Thor 雷神 SchaeffandCharis authored and GitHub committed 2024-01-10 07:48:05 +00:00
1 parent ef651aa9ba
commit 32771601ce
3 files changed
+232 -2

No files matched your search

@@ -237,12 +237,14 @@ export const gettingstarted: NavMenuConstant = {
{ name: 'Next.js', url: '/guides/getting-started/quickstarts/nextjs' },
{ name: 'React', url: '/guides/getting-started/quickstarts/reactjs' },
{ name: 'NuxtJS', url: '/guides/getting-started/quickstarts/nuxtjs' },
{ name: 'RedwoodJS', url: '/guides/getting-started/quickstarts/redwoodjs' },
{ name: 'Vue', url: '/guides/getting-started/quickstarts/vue' },
{ name: 'Flutter', url: '/guides/getting-started/quickstarts/flutter' },
{ name: 'Android Kotlin', url: '/guides/getting-started/quickstarts/kotlin' },
{ name: 'SvelteKit', url: '/guides/getting-started/quickstarts/sveltekit' },
{ name: 'Laravel PHP', url: '/guides/getting-started/quickstarts/laravel' },
{ name: 'Ruby on Rails', url: '/guides/getting-started/quickstarts/ruby-on-rails' },
{ name: 'SolidJS', url: '/guides/getting-started/quickstarts/solidjs' },
{ name: 'Vue', url: '/guides/getting-started/quickstarts/vue' },
{ name: 'RedwoodJS', url: '/guides/getting-started/quickstarts/redwoodjs' },
{ name: 'refine', url: '/guides/getting-started/quickstarts/refine' },
],
},
@@ -0,0 +1,111 @@
import Layout from '~/layouts/DefaultGuideLayout'
import StepHikeCompact from '~/components/StepHikeCompact'
export const meta = {
title: 'Use Supabase with Laravel',
subtitle:
'Learn how to create a PHP Laravel project, connect it to your Supabase Postgres database, and configure user authentication.',
breadcrumb: 'Framework Quickstarts',
}
<StepHikeCompact>
<StepHikeCompact.Step step={1}>
<StepHikeCompact.Details title="Create a Laravel Project">
Make sure your PHP and Composer versions are up to date, then use `composer create-project` to scaffold a new Laravel project.
See the [Laravel docs](https://laravel.com/docs/10.x/installation#creating-a-laravel-project) for more details.
</StepHikeCompact.Details>
<StepHikeCompact.Code>
```bash Terminal
composer create-project laravel/laravel example-app
```
</StepHikeCompact.Code>
</StepHikeCompact.Step>
<StepHikeCompact.Step step={2}>
<StepHikeCompact.Details title="Install the Authentication template">
Install [Laravel Breeze](https://laravel.com/docs/10.x/starter-kits#laravel-breeze), a simple implementation of all of Laravel's [authentication features](https://laravel.com/docs/10.x/authentication).
</StepHikeCompact.Details>
<StepHikeCompact.Code>
```bash Terminal
composer require laravel/breeze --dev
php artisan breeze:install
```
</StepHikeCompact.Code>
</StepHikeCompact.Step>
<StepHikeCompact.Step step={3}>
<StepHikeCompact.Details title="Set up the Postgres connection details">
Go to [database.new](https://database.new) and create a new Supabase project. Save your database password securely.
When your project is up and running, navigate to the [database settings](https://supabase.com/dashboard/project/_/settings/database) to find the URI connection string.
Laravel ships with a Postgres adapter out of the box, you can simply configure it via the environment variables. You can find the database URL in your [Supabase Dashboard](/dashboard/project/_/settings/database).
</StepHikeCompact.Details>
<StepHikeCompact.Code>
```bash .env
DB_CONNECTION=pgsql
DATABASE_URL=postgresql://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres
```
</StepHikeCompact.Code>
</StepHikeCompact.Step>
<StepHikeCompact.Step step={4}>
<StepHikeCompact.Details title="Run the database migrations">
Laravel ships with database migration files that set up the required tables for Laravel Authentication and User Management.
Note: Laravel does not use Supabase Auth but rather implements its own authentication system!
</StepHikeCompact.Details>
<StepHikeCompact.Code>
```bash Terminal
php artisan migrate
```
</StepHikeCompact.Code>
</StepHikeCompact.Step>
<StepHikeCompact.Step step={5}>
<StepHikeCompact.Details title="Start the app">
Run the development server. Go to http://127.0.0.1:8000 in a browser to see your application. You can also nvaigate to http://127.0.0.1:8000/register and http://127.0.0.1:8000/login to register and log in users.
</StepHikeCompact.Details>
<StepHikeCompact.Code>
```bash Terminal
php artisan serve
```
</StepHikeCompact.Code>
</StepHikeCompact.Step>
</StepHikeCompact>
export const Page = ({ children }) => <Layout meta={meta} children={children} hideToc={true} />
export default Page
@@ -0,0 +1,117 @@
import Layout from '~/layouts/DefaultGuideLayout'
import StepHikeCompact from '~/components/StepHikeCompact'
export const meta = {
title: 'Use Supabase with Ruby on Rails',
subtitle:
'Learn how to create a Rails project and connect it to your Supabase Postgres database.',
breadcrumb: 'Framework Quickstarts',
}
<StepHikeCompact>
<StepHikeCompact.Step step={1}>
<StepHikeCompact.Details title="Create a Rails Project">
Make sure your Ruby and Rails versions are up to date, then use `rails new` to scaffold a new Rails project. Use the `-d=postgresql` flag to set it up for Postgres.
Go to the [Rails docs](https://guides.rubyonrails.org/getting_started.html) for more details.
</StepHikeCompact.Details>
<StepHikeCompact.Code>
```bash Terminal
rails new blog -d=postgresql
```
</StepHikeCompact.Code>
</StepHikeCompact.Step>
<StepHikeCompact.Step step={2}>
<StepHikeCompact.Details title="Set up the Postgres connection details">
Go to [database.new](https://database.new) and create a new Supabase project. Save your database password securely.
When your project is up and running, navigate to the [database settings](https://supabase.com/dashboard/project/_/settings/database) to find the URI connection string.
Rails ships with a Postgres adapter included, you can simply configure it via the environment variables. You can find the database URL in your [Supabase Dashboard](/dashboard/project/_/settings/database).
</StepHikeCompact.Details>
<StepHikeCompact.Code>
```bash Terminal
export DATABASE_URL=postgresql://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres
```
</StepHikeCompact.Code>
</StepHikeCompact.Step>
<StepHikeCompact.Step step={3}>
<StepHikeCompact.Details title="Create and run a database migration">
Rails includes Active Record as the ORM as well as database migration tooling which generates the SQL migration files for you.
Create an example `Article` model and generate the migration files.
</StepHikeCompact.Details>
<StepHikeCompact.Code>
```bash Terminal
bin/rails generate model Article title:string body:text
bin/rails db:migrate
```
</StepHikeCompact.Code>
</StepHikeCompact.Step>
<StepHikeCompact.Step step={4}>
<StepHikeCompact.Details title="Use the Model to interact with the database">
You can use the included Rails console to interact with the database. For example, you can create new entries or list all entries in a Model's table.
</StepHikeCompact.Details>
<StepHikeCompact.Code>
```bash Terminal
bin/rails console
```
```rb irb
article = Article.new(title: "Hello Rails", body: "I am on Rails!")
article.save # Saves the entry to the database
Article.all
```
</StepHikeCompact.Code>
</StepHikeCompact.Step>
<StepHikeCompact.Step step={5}>
<StepHikeCompact.Details title="Start the app">
Run the development server. Go to http://127.0.0.1:3000 in a browser to see your application running.
</StepHikeCompact.Details>
<StepHikeCompact.Code>
```bash Terminal
bin/rails server
```
</StepHikeCompact.Code>
</StepHikeCompact.Step>
</StepHikeCompact>
export const Page = ({ children }) => <Layout meta={meta} children={children} hideToc={true} />
export default Page