Skip to content

Instantly share code, notes, and snippets.

@helloworldlab
Last active July 21, 2025 22:06
Show Gist options
  • Select an option

  • Save helloworldlab/3fc4084f6568060c791c2f6fc65f3cb3 to your computer and use it in GitHub Desktop.

Select an option

Save helloworldlab/3fc4084f6568060c791c2f6fc65f3cb3 to your computer and use it in GitHub Desktop.
Install Bootstrap 5.3 on Laravel
<?php
Component::macro(
'notifikasi',
function ($tajuk = null, $isiKandungan = null, $tindakan = null) {
$js = '';
if (filled($tajuk)) {
$js .= "document.getElementById('tajuk-notifikasi-sistem').innerHTML = '';";
$js .= "document.getElementById('tajuk-notifikasi-sistem').innerHTML = '{$tajuk}';";
}
if (filled($isiKandungan)) {
$js .= "document.getElementById('isi-kandungan-notifikasi-sistem').innerHTML = '';";
$js .= "document.getElementById('isi-kandungan-notifikasi-sistem').innerHTML = '{$isiKandungan}';";
}
if (filled($tindakan)) {
$js .= "document.getElementById('tindakan-notifikasi-sistem').innerHTML = '';";
$js .= "document.getElementById('tindakan-notifikasi-sistem').innerHTML = '{$tindakan}';";
}
$js .= "const modalNotifikasiSistem = bootstrap.Modal.getOrCreateInstance('#modal-notifikasi-sistem');modalNotifikasiSistem.show();";
$this->js($js);
}
);
  1. Install popper js and bootstrap.
npm i --save-dev @popperjs/core [email protected] sass
  1. Rename resources/css to resources/scss and resources/css/app.css to resources/scss/app.scss.
@import "bootstrap/scss/bootstrap";
  1. Import all JavaScript plugins.
import * as bootstrap from 'bootstrap';
window.bootstrap = bootstrap;
  1. Replace code in vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/scss/app.scss', 'resources/js/app.js'],
            refresh: true,
        }),
    ],
});
  1. Build the assets.
npm run build
  1. Use the assets.
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>{{ $title ?? 'Page Title' }}</title>
        @vite(['resources/scss/app.scss', 'resources/js/app.js'])
    </head>
    <body>
        {{ $slot }}
    </body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment