0% found this document useful (0 votes)
8 views26 pages

Tutorial Projek Mobil

This document is a tutorial for creating a car sales application using Laravel. It outlines steps for setting up the project, installing necessary packages, creating models and migrations, configuring resources for cars, customers, sales, and users, and implementing CRUD operations. The tutorial includes specific commands and code snippets for each step to guide the user through the development process.

Uploaded by

rafiwitama05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views26 pages

Tutorial Projek Mobil

This document is a tutorial for creating a car sales application using Laravel. It outlines steps for setting up the project, installing necessary packages, creating models and migrations, configuring resources for cars, customers, sales, and users, and implementing CRUD operations. The tutorial includes specific commands and code snippets for each step to guide the user through the development process.

Uploaded by

rafiwitama05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

TUTORIAL PENJUALAN MOBIL

Nama : Rafaizal Firdaus Arbiansyah


Kelas : XI PPLG 1
Absen : 29

1. Buat Folder Project


mkdir projek_akhir2
cd projek_akhir2

2. Install Laravel
composer create-project laravel/laravel="10.*" .

3. Buat Database dan masuk ke direktori project

4. Sesuaikan database di file .env


5. Install Filament
composer require filament/filament:"^3.3" -W

6. Jalankan migrasi database


php artisan migrate

7. Buat Model dan Migration

 Generate Model Car


php artisan make:model Car -m

 Generate Model Customer


php artisan make:model Customer -m

 Generate Model Sale


php artisan make:model Sale -m

8. Konfigurasi Migration Users


Edit Migration Users Buka file database/migrations/xxxx_create_users_table.php dan
ganti isinya dengan:

9. Konfigurasi Migration Cars


Edit Migration Cars Buka file database/migrations/xxxx_create_cars_table.php dan ganti
isinya dengan:

10. Konfigurasi Migration Customers


Edit Migration Customers Buka file database/migrations/xxxx_create_customers_table.php
dan ganti isinya dengan:

11. Konfigurasi Migration Sales


Edit Migration Sales Buka file database/migrations/xxxx_create_sales_table.php dan ganti
isinya dengan:

12. Konfigurasi Model Car


Edit Model Car Buka file app/Models/[Link] dan ganti isinya dengan:

13. Konfigurasi Model Customer


Edit Model Customer Buka file app/Models/[Link] dan ganti isinya dengan:

14. Konfigurasi Model Sale


Edit Model Sale Buka file app/Models/[Link] dan ganti isinya dengan:

15. Konfigurasi Model User


Edit Model User Buka file app/Models/[Link] dan ganti isinya dengan:

16. Buat Seeder


Edit Database Seeder Buka file database/seeders/[Link] dan ubah method run():

17. Jalankan Migration dan Seeder


php artisan migrate –seed

18. Buat Car Resource

Generate Car Resource


php artisan make:filament-resource Car

Edit Car Resource Buka file app/Filament/Resources/[Link] dan copy-paste kode


<?php

namespace App\Filament\Resources;

use App\Filament\Resources\CarResource\Pages;
use App\Filament\Resources\CarResource\RelationManagers;
use App\Models\Car;
use Filament\Forms;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Tables\Columns\TextColumn;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class CarResource extends Resource


{
protected static ?string $model = Car::class;

protected static ?string $navigationGroup = 'Master Data';

protected static ?string $navigationLabel = 'Mobil';

protected static ?string $label = 'Mobil';


protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form


{
return $form
->schema([
TextInput::make('brand')
->required()
->label('Merek Mobil')
->maxLength(255),

TextInput::make('type')
->required()
->label('Model Mobil')
->maxLength(255),

TextInput::make('year')
->required()
->label('Tahun Pembuatan')
->maxLength(4)
->minValue(1886)
->maxValue(now()->year)
->numeric(),

TextInput::make('color')
->required()
->label('Warna Mobil')
->maxLength(255),

TextInput::make('license_plate')
->required()
->label('Plat Nomer')
->maxLength(20),

TextInput::make('no_chassis')
->required()
->label('kode Rangka')
->maxLength(255),

TextInput::make('no_engine')
->required()
->label('Kode mesin')
->maxLength(255),

TextInput::make('price')
->required()
->label('Harga Mobii')
->numeric()
->minValue(0)
->maxValue(999999999.99)
->step(0.01),

Select::make('status')
->required()
->label('Status mobil')
->options([
'available' => 'Available',
'sold' => 'Sold',
])
->default('available'),

Textarea::make('description')
->label('Deskripsi Mobil')
->maxLength(65535)
->rows(3)
->columnSpan(2)
]);
}

public static function table(Table $table): Table


{
return $table
->columns([
TextColumn::make('brand')
->label('Merek Mobil')
->sortable()
->searchable(),

TextColumn::make('type')
->label('Model Mobil')
->sortable()
->searchable(),

TextColumn::make('price')
->label('Harga Mobil')
->sortable()
->money('USD', true),

TextColumn::make('status')
->label('Status Mobil')
->sortable()
->searchable()
->color(fn(string $state): string => match ($state) {
'sold' => 'danger',
'available' => 'success',
}),

])
->filters([
Tables\Filters\SelectFilter::make('status')
->options([
'available' => 'Available',
'sold' => 'Sold',
])

])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\Action::make('delete')
->label('Hapus')
->action(fn(Car $record) => $record->delete())
->disabled(fn(Car $record) => $record->status === 'sold'),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array


{
return [

];
}

public static function getPages(): array


{
return [
'index' => Pages\ListCars::route('/'),
'create' => Pages\CreateCar::route('/create'),
'edit' => Pages\EditCar::route('/{record}/edit'),
];

Edit [Link] Buka file app/Filament/Resources/CarResource/Pages/[Link]

Edit [Link] Buka file app/Filament/Resources/CarResource/Pages/[Link]

19. Buat Customer Resource


Generate Customer Resource
php artisan make:filament-resource Customer

Edit Customer Resource Buka file app/Filament/Resources/[Link] dan copy-


paste kode

<?php

namespace App\Filament\Resources;

use App\Filament\Resources\CustomerResource\Pages;
use App\Filament\Resources\CustomerResource\RelationManagers;
use App\Models\Customer;
use Filament\Forms;
use Filament\Forms\Components;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Tables\Columns;
use Filament\Tables\Columns\TextColumn;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

use function Laravel\Prompts\form;

class CustomerResource extends Resource


{
protected static ?string $model = Customer::class;

protected static ?string $navigationGroup = 'Master Data';

protected static ?string $navigationLabel = 'Customer';

protected static ?string $label = 'Customer';


protected static ?string $navigationIcon = 'heroicon-o-users';

public static function form(Form $form): Form


{
return $form
->schema([
TextInput::make('name')
->required()
->maxLength(255)
->label('Nama Custumor'),

TextInput::make('phone')
->required()
->maxLength(15)
->tel()
->label('Nomor HP'),

TextArea::make('address')
->required()
->label('Alamat')
->rows(3)
->columnSpan(2)
]);
}

public static function table(Table $table): Table


{
return $table
->columns([
TextColumn::make('name')
->label('Nama Customer')
->searchable()
->sortable(),

TextColumn::make('phone')
->label('Nomor HP')
->searchable(),

TextColumn::make('address')
->label('Alamat')
->searchable()
->limit(40)
->wrap(),
])
->filters([
//
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array


{
return [
//
];
}

public static function getPages(): array


{
return [
'index' => Pages\ListCustomers::route('/'),
'create' => Pages\CreateCustomer::route('/create'),
'edit' => Pages\EditCustomer::route('/{record}/edit'),
];
}
}

Edit [Link] Buka file


app/Filament/Resources/CustomerResource/Pages/[Link]
Edit [Link]
Buka file app/Filament/Resources/CustomerResource/Pages/[Link]

20. Buat Sale Resource

Generate Sale Resource


php artisan make:filament-resource Sale

Edit Sale Resource Buka file app/Filament/Resources/[Link] dan copy-paste kode

<?php

namespace App\Filament\Resources;

use App\Filament\Resources\SaleResource\Pages;
use App\Filament\Resources\SaleResource\RelationManagers;
use App\Models\Sale;
use Filament\Forms;
use App\Models\Car;
use Filament\Forms\Form;
use Filament\Forms\Components\DatePicker;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Tables\Columns;
use Filament\Tables\Columns\TextColumn;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class SaleResource extends Resource


{
protected static ?string $model = Sale::class;

protected static ?string $navigationGroup = 'Master Data';


protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

protected static ?string $navigationLabel = 'Penjualan';

protected static ?string $label = 'Penjualan';

public static function form(Form $form): Form


{
return $form
->schema([
Select::make('car_id')
->relationship('car', 'type')
->options(
Car::where('status', 'available')->pluck('type', 'id')
)
->searchable()
->preload()
->required()
->live()
->afterStateUpdated(function ($state, Forms\Set $set) {
$car = Car::find($state);
$set('sale_price', $car?->price ?? 0);
}),

Select::make('customer_id')
->relationship('customer', 'name')
->searchable()
->preload()
->live()
->required(),

Select::make('user_id')
->relationship('user', 'name')
->searchable()
->preload()
->live()
->required(),

TextInput::make('sale_price')
->label('Harga Jual')
->required()
->readonly(),

DatePicker::make('sale_date')
->label('Tanggal Penjualan')
->required()
->date(),

Select::make('payment_method')
->label('Metode Pembayaran')
->options([
'cash' => 'Tunai',
'credit_card' => 'Kartu Kredit',
'bank_transfer' => 'Transfer Bank',
])
->required(),
]);
}

public static function table(Table $table): Table


{
return $table
->columns([
TextColumn::make('[Link]')
->label('Model Mobil')
->sortable()
->searchable(),

TextColumn::make('[Link]')
->label('Nama Customer')
->sortable()
->searchable(),

TextColumn::make('[Link]')
->label('Nama Pekerja')
->sortable()
->searchable(),

TextColumn::make('sale_price')
->label('Harga Penjualan')
->money()
->sortable(),

TextColumn::make('sale_date')
->label('Tanggal Penjualan')
->date()
->sortable(),
])
->filters([
//
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array


{
return [
//
];
}

public static function getPages(): array


{
return [
'index' => Pages\ListSales::route('/'),
'create' => Pages\CreateSale::route('/create'),
'edit' => Pages\EditSale::route('/{record}/edit'),
];
}
}
Edit [Link] Buka file app/Filament/Resources/SaleResource/Pages/[Link]

Edit [Link]
Buka file app/Filament/Resources/SaleResource/Pages/[Link]
21. Buat User Resource

Generate User Resource


php artisan make:filament-resource User

Edit User Resource Buka file app/Filament/Resources/[Link] dan copy-paste


kode

<?php

namespace App\Filament\Resources;

use App\Filament\Resources\UserResource\Pages;
use App\Filament\Resources\UserResource\RelationManagers;
use App\Models\User;
use Filament\Forms;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Illuminate\Support\Facades\Hash;
use Filament\Tables;
use Filament\Forms\Components\TextInput;
use Filament\Tables\Table;
use Filament\Tables\Columns\TextColumn;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class UserResource extends Resource


{
protected static ?string $model = User::class;

protected static ?string $navigationGroup = 'Master Data';


protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

protected static ?string $navigationLabel = 'Pekerja';

protected static ?string $label = 'Pekerja';


public static function canAccess(): bool
{
return auth()->user()->isAdmin();
}

public static function form(Form $form): Form


{
return $form
->schema([
TextInput::make('name')
->label('Nama')
->required()
->maxLength(255),

TextInput::make('email')
->label('Email')
->email()
->required()
->maxLength(255)
->unique(ignoreRecord: true),

TextInput::make('password')
->password()
->dehydrateStateUsing(fn($state) => Hash::make($state))
->dehydrated(fn($state) => filled($state))
->required(fn(string $operation): bool => $operation === 'create'),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->label('Nama')
->sortable()
->searchable(),
TextColumn::make('email')
->label('Email')
->sortable()
->searchable(),
TextColumn::make('role')
->label('Divisi')
->sortable()
->searchable()
->badge()
->color(fn(string $state): string => match ($state) {
'admin' => 'danger',
'employee' => 'success',
}),
])
->filters([
Tables\Filters\SelectFilter::make('role')
->options([
'admin' => 'Admin',
'employee' => 'employee',
])
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array


{
return [
//
];
}

public static function getPages(): array


{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}
}
Edit [Link]
Buka file app/Filament/Resources/UserResource/Pages/[Link]

Edit [Link]
Buka file app/Filament/Resources/UserResource/Pages/[Link]
22. Buat Stats Widget
php artisan make:filament-widget StatsOverview --stats-overview

Edit Stats Widget Buka file app/Filament/Widgets/[Link]

23. Buat Chart Widget


php artisan make:filament-widget SalesChart –chart

Pilih option "3" untuk Line Chart.


Edit Chart Widget Buka file app/Filament/Widgets/[Link]
24. Konfigurasi Admin Panel

Edit Admin Panel Provider Buka file app/Providers/Filament/[Link]


DOKUMENTASI HASIL

You might also like