News

Loading...

Community Links

Laravel Jobs

Latest News

Loading...

Latest Partners

Loading...

Partners

Loading...

Panduan Lengkap Setup Laravel 11 dengan Best Practice Modern (Vite, Breeze, Sanctum, dan More)


Tutorial step‑by‑step ini menjelaskan cara menginstal Laravel 11 terbaru, mengintegrasikan Vite, Breeze, Laravel Sanctum, serta konfigurasi best practice untuk pengembangan aplikasi web modern di tahun 2026.

1. Prasyarat

Pastikan sistem Anda sudah terpasang:

  • PHP ^8.2
  • Composer 2.x
  • Node.js 20.x & npm 10.x
  • Git

2. Instalasi Laravel 11

composer create-project laravel/laravel my-app "11.*"

Perintah ini mengunduh Laravel 11 dengan semua dependensi default.

2.1. Masuk ke Direktori Proyek

cd my-app

3. Setup Frontend dengan Vite

Laravel 11 sudah menggunakan Vite secara default, namun pastikan konfigurasi berikut:

  1. Instalasi dependensi npm:
npm install

Jika Anda ingin menambahkan Vue 3 atau React, jalankan:

# Vue 3
npm install vue@next @vitejs/plugin-vue
# React
npm install react react-dom @vitejs/plugin-react

3.1. Konfigurasi vite.config.js

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue'; // atau react()

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
        vue(), // hapus bila tidak pakai Vue
    ],
});

4. Instalasi Laravel Breeze (Auth Starter Kit)

composer require laravel/breeze --dev
php artisan breeze:install vue   # atau react, blade
npm run dev

Breeze menyediakan scaffolding autentikasi lengkap dengan komponen Vue/React atau Blade.

4.1. Migrasi Database

php artisan migrate

5. Integrasi Laravel Sanctum untuk API Token & SPA Authentication

composer require laravel/sanctum
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
php artisan migrate

Tambahkan middleware Sanctum::class pada api guard di config/auth.php:

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],
    'api' => [
        'driver' => 'sanctum',
        'provider' => 'users',
    ],
],

5.1. Menggunakan SPA Authentication

Di resources/js/app.js (Vue contoh):

import { createApp } from 'vue';
import { InertiaApp } from '@inertiajs/inertia-vue3';
import { InertiaProgress } from '@inertiajs/progress';

const app = createApp({
    render: () => h(InertiaApp, {
        initialPage: JSON.parse(app.dataset.page),
        resolveComponent: name => import(`./Pages/${name}`).then(module => module.default),
    })
});

app.mount('#app');
InertiaProgress.init();

Sanctum otomatis mengirim cookie XSRF-TOKEN untuk melindungi request AJAX.

6. Best Practice Modern

  • Environment Variables: Simpan rahasia di .env dan gunakan vapor atau docker untuk isolasi.
  • Database Migrations & Seeders: Selalu versioning schema dengan php artisan migrate:fresh --seed pada CI.
  • Static Analysis: Pasang phpstan dan larastan untuk tipe safety.
  • Testing: Tulis unit & feature test menggunakan php artisan test; CI pipeline harus menolak tanpa coverage >80%.
  • Code Styling: Gunakan Laravel Pint (vendor/bin/pint) untuk konsistensi.
  • Cache Configuration: Aktifkan redis untuk cache, queue, dan session di .env:
CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_CONNECTION=redis

7. Deploy ke Production

  1. Build assets: npm run build
  2. Optimasi autoloader: composer install --optimize-autoloader --no-dev
  3. Migrate database: php artisan migrate --force
  4. Clear caches: php artisan config:cache && php artisan route:cache && php artisan view:cache

Gunakan platform seperti Laravel Vapor, Forge, atau Docker Swarm untuk skalabilitas.

8. Penutup

Dengan mengikuti langkah‑langkah di atas, Anda memiliki fondasi Laravel 11 yang modern, aman, dan siap untuk pengembangan aplikasi web skala besar pada tahun 2026.


Laravel 11 bersama Vite, Breeze, dan Sanctum memberikan stack lengkap untuk membangun aplikasi modern dengan performa tinggi. Terapkan best practice seperti environment management, testing otomatis, dan cache Redis untuk memastikan kode Anda tetap scalable, maintainable, dan siap produksi.
Tutorial step-by-step instalasi Laravel 11 terbaru dengan Vite, Breeze, Sanctum, serta best practice modern untuk pengembangan web di 2026.

Laravel,PHP Framework,Web Development

#Laravel #LaravelIndonesia #PHP #WebDev #Backend

Tidak ada komentar:

Posting Komentar

Most Read

Loading...

Tutorial

Loading...

Packages

Loading...