Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
- Simple, fast routing engine.
- Powerful dependency injection container.
- Multiple back-ends for session and cache storage.
- Expressive, intuitive database ORM.
- Database agnostic schema migrations.
- Robust background job processing.
- Real-time event broadcasting.
Laravel is accessible, powerful, and provides tools required for large, robust applications.
- Clone Repository ini dengan cara `git clone https://github.com/m
- Buka folder project di terminal dan jalankan perintah composer install
- Setup database sesuai kebutuhan (Buat database baru dan setting di .env)
- Jalankan perintah
php artisan key:generate untuk generate
- Jalankan
perintah php artisan migrate --seed
untuk melakukan migration dan seeding data ke database
- Jika ingin menambahkan fitur lainnya seperti user authentication maka dapat mengikuti tutorial pada link berikut :
- Jika ingin menggunakan fitur email verification maka jalankan perintah php artisan make:mail VerifyEmail dan pastikan file tersebut sudah diisi dengan code yang benar. Kemudian buka file App\Providers\AppServiceProvider.php dan pastikan file app\Mail\VerifyEmail.php sudah terisi dengan code yang benar. Kemudian buka file App\User.php dan
- Pastikan semua konfigurasinya sudah benar lalu jalankan server local dengan perintah php artisan serve Note : Untuk menampilkan data user yang telah terdaftar silahkan buka halaman /users dan masukkan username dan password yang
- Login & Register with Email Verification
- Forgot Password
- Reset Password
- User Profile
- Admin Dashboard
- CRUD Products
- Shopping Cart
- Checkout Process (Stripe Payment Gateway)
- Categories Page
- Blog Posts with Pagination
- Contact Form
Untuk Stripe Payment Gateway saya gunakan package dari laravel official yaitu Laravel\Cashier\CashierServiceProvider
. Unt
Untuk fitur payment gateway saya gunakan Stripe sebagai contoh. Untuk implementasi lainnya silahkan diganti dengan yan
Saya tidak menyertakan gambaran UI karena saya lebih fokus pada implementasi logikanya. Namun, jika Anda memer
Untuk fitur Stripe Payment Gateway, silahkan register di stripe.com, setelah
Saya tidak menyertakan gambaran UI karena saya lebih fokus pada implementasi logikanya. Namun jika Anda ingin memb
Untuk Stripe Payment Gateway yang digunakan pada saat checkout process, silahkan register di stripe.com dan masukkan skripny
Untuk Stripe Payment Gateway saya gunakan Sandbox, jadi Anda tidak akan dikenakan biaya apapun. Namun jika ingin menggunakan produksi, Anda harus membuat account
Untuk fitur Stripe Payment Gateway, silahkan register di stripe.com dan masukkan skrip yang ada pada file .env
</
Untuk fitur payment gateway saya gunakan Stripe sebagai contoh. Untuk implementasi lainnya silahkan ganti pada file
Saya tidak menyertakan gambaran UI karena saya lebih fokus pada implementasi logikanya. Namun jika Anda ingin memb
Untuk fitur Stripe Payment Gateway, Anda harus membuat account di Stripe dan memasang package stripe/stripe-php versi
- install proyek
laravel new laravel-ecommerce
composer create-project laravel/laravel nama-proyek
- instal Livewire, Jetstream, Mysql, Stripe dan Composer
composer require laravel/jetstream
php artisan jetstream:install livewire
- konfigurasi peran
'roles' => [
'super-admin' => 'Super Admin',
'admin' => 'Admin',
'pegawai' => 'Pegawai',
'user' => 'User',
],
- Jalankan Migration
php artisan migrate
- Tambahkan Kolom Peran: Buka file database/migrations/xxxx_xx_xx_create_users_table.php dan tambahkan kolom peran ke dalam fungsi up():
Schema::create('users', function (Blueprint $table) {
$table->id();
// kolom-kolom lainnya
$table->string('role')->default('user');
$table->timestamps();
});
php artisan migrate
- Tambahkan Middleware, Buka file app/Http/Kernel.php dan tambahkan middleware sesuai dengan peran yang diinginkan. Contohnya:
'admin' => \App\Http\Middleware\AdminMiddleware::class,
'pegawai' => \App\Http\Middleware\PegawaiMiddleware::class,
'super-admin' => \App\Http\Middleware\SuperAdminMiddleware::class,
- Buat Middleware: Buat middleware untuk masing-masing peran di dalam direktori app/Http/Middleware. Contoh untuk AdminMiddleware.php:
public function handle(Request $request, Closure $next)
{
if (auth()->user() && auth()->user()->role == 'admin') {
return $next($request);
}
abort(403, 'Unauthorized');
}
- Tambahkan Peran ke Model User: Buka file app/Models/User.php dan tambahkan metode untuk menentukan apakah pengguna memiliki peran tertentu:
public function isAdmin()
{
return $this->role === 'admin';
}
public function isPegawai()
{
return $this->role === 'pegawai';
}
public function isSuperAdmin()
{
return $this->role === 'super-admin';
}
- Gunakan Middleware pada Route: Gunakan middleware yang telah dibuat pada rute-rute yang memerlukan autentikasi berdasarkan peran:
use App\Http\Controllers\FrontendController;
// Rute Frontend
Route::get('/', [FrontendController::class, 'index'])->name('home-fe');
// Rute Dashboard yang memerlukan autentikasi
Route::middleware([
'auth:sanctum',
config('jetstream.auth_session'),
'verified',
])->group(function () {
// Rute Dashboard untuk User Biasa
Route::get('/dashboard', function () {
return view('dashboard');
})->name('dashboard');
// Rute Dashboard untuk Admin
Route::middleware(['admin'])->group(function () {
Route::get('/admin/dashboard', function () {
return view('admin.dashboard');
})->name('admin.dashboard');
});
// Rute Dashboard untuk Pegawai
Route::middleware(['pegawai'])->group(function () {
Route::get('/pegawai/dashboard', function () {
return view('pegawai.dashboard');
})->name('pegawai.dashboard');
});
// Rute Dashboard untuk Super Admin
Route::middleware(['super-admin'])->group(function () {
Route::get('/super-admin/dashboard', function () {
return view('super-admin.dashboard');
})->name('super-admin.dashboard');
});
});
- Simpan Peran pada Pendaftaran: Buka file app/Http/Controllers/Auth/RegisterController.php dan tambahkan logika untuk menyimpan peran:
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'role' => $data['role'], // Simpan peran
]);
}
- Gunakan Peran pada Middleware (Opsional): Jika Anda ingin menggunakan peran pada middleware, Anda dapat mengubah middleware sesuai dengan peran yang disimpan di sesi:
'admin' => \App\Http\Middleware\AdminMiddleware::class,
'pegawai' => \App\Http\Middleware\PegawaiMiddleware::class,
'super-admin' => \App\Http\Middleware\SuperAdminMiddleware::class,
php artisan make:seeder UsersTableSeeder
- Edit Seeder: Buka file database/seeders/UsersTableSeeder.php dan edit metode run seperti berikut:
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use App\Models\User;
class UsersTableSeeder extends Seeder
{
public function run()
{
// Super Admin
User::create([
'name' => 'Super Admin',
'email' => '[email protected]',
'password' => Hash::make('superadmin123456'),
'role' => 'super-admin',
]);
// Admin
User::create([
'name' => 'Admin',
'email' => '[email protected]',
'password' => Hash::make('admin123456'),
'role' => 'admin',
]);
// Pegawai
User::create([
'name' => 'Pegawai',
'email' => '[email protected]',
'password' => Hash::make('pegawai123456'),
'role' => 'pegawai',
]);
// User Biasa
User::create([
'name' => 'User Biasa',
'email' => '[email protected]',
'password' => Hash::make('user123456'),
'role' => 'user',
]);
}
}
- Jalankan Seeder:
php artisan db:seed --class=UsersTableSeeder
Laravel has the most extensive and thorough documentation and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
You may also try the Laravel Bootcamp, where you will be guided through building a modern Laravel application from scratch.
If you don't feel like reading, Laracasts can help. Laracasts contains over 2000 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel Partners program.
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the Laravel documentation.
In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [email protected]. All security vulnerabilities will be promptly addressed.
The Laravel framework is open-sourced software licensed under the MIT license.