0% found this document useful (0 votes)
17 views12 pages

Nuyy

Uploaded by

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

Nuyy

Uploaded by

bwh55mfyw4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Secret File

1. install laravel:
create-project laravel/laravel:^9.5 nama_projek

2. login register: //buka visual studio code buka nama_projek lalu


buka terminal dan ketikan
satu persatu

composer require laravel/ui


php artisan ui bootstrap
php artisan ui bootstrap --auth
npm install
npm run dev
Buat Terminal baru
php artisan serve
kade poho

3. buat database
jieun database kosong hela di phpmyadmin

masukan ke file env

Buka terminal ketikan

php artisan make:model siswa -m


Buka model siswa di

Abuskeun kode iyeu

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Kyslik\ColumnSortable\Sortable;

class siswa extends Model


{
use HasFactory, Sortable;
protected $table = 'siswa';
protected $guarded = [
'id'
];
public $timestamp = false;
}
Buka File na di

ABUSKEEUN CODE IYEU


<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('siswa', function (Blueprint $table) {
$table->id();
$table->integer('nis');
$table->unique('nis');
$table->string('nama');
$table->string('jurusan');
$table->string('tempat_lahir');
$table->date('tanggal_lahir');
$table->string('foto')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('siswa');
}
};
Buka Terminal ketikeun
php artisan migrate

4. controller
ketikeun di terminal

php artisan make:controller siswaController --resource

Buka file na di
ABUSKEEUN CODE IYEU
<?php
namespace App\Http\Controllers;
use App\Models\siswa;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Storage;
class siswaController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$katakunci = $request->katakunci;
$jumlah_baris = 4;
if (strlen($katakunci)) {
$data = siswa::sortable()->where('nis', 'like', "%$katakunci%")
->orWhere('nama', 'like', "%$katakunci%")
->orWhere('jurusan', 'like', "%$katakunci%")
->orWhere('tempat_lahir', 'like', "%$katakunci%");
} else {
$data = siswa::sortable();
}
return view('siswa.index')->with('data', $data->paginate($jumlah_baris));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('siswa.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
Session::flash('nis', $request->nis);
Session::flash('nama', $request->nama);
Session::flash('jurusan', $request->jurusan);
Session::flash('tempat_lahir', $request->tempat_lahir);
Session::flash('tanggal_lahir', $request->tanggal_lahir);
$request->validate([
'nis' => 'required|numeric|unique:siswa,nis',
'nama' => 'required',
'jurusan' => 'required',
'tempat_lahir' => 'required',
'tanggal_lahir' => 'required',
'foto' => 'image|file|max:2048',
]);
$data = [
'nis' => $request->nis,
'nama' => $request->nama,
'jurusan' => $request->jurusan,
'tempat_lahir' => $request->tempat_lahir,
'tanggal_lahir' => $request->tanggal_lahir,
];
if ($request->foto) {
$data['foto'] = $request->file('foto')->store('profile');
}
siswa::create($data);
return redirect()->to('siswa')->with('success', 'Data berhasil disimpan');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$data = siswa::where('nis', $id)->first();
return view('siswa.edit')->with('data', $data);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$request->validate([
'nis' => 'required|numeric',
'nama' => 'required',
'jurusan' => 'required',
'tempat_lahir' => 'required',
'tanggal_lahir' => 'required',
'foto' => 'image|file|max:2048',
]);
$data = [
'nis' => $request->nis,
'nama' => $request->nama,
'jurusan' => $request->jurusan,
'tempat_lahir' => $request->tempat_lahir,
'tanggal_lahir' => $request->tanggal_lahir,
'foto' => $request->fotolama,
];
if ($request->file('foto')) {
if ($request->fotolama) {
Storage::delete($request->fotolama);
}
$data['foto'] = $request->file('foto')->store('profile');
}
siswa::where('nis', $id)->update($data);
return redirect()->to('siswa')->with('success', 'Data berhasil diperbarui');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$data = siswa::where('nis', $id)->get();
if ($data[0]->foto) {
Storage::delete($data[0]->foto);
}
siswa::where('nis', $id)->delete();
return redirect()->to('siswa')->with('success', 'Data berhasil dihapus');
}
}
BUKA FILE ROUTE WEB DI

ABUSKEUN CODE IYEU

<?php
use App\Http\Controllers\siswaController;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});

Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])-
>name('home');
Route::resource('/siswa', siswaController::class);
5. FOLDER SISWA

Nyieun folder siswa isi na create , edit ,index


jeungfolder komponen

ISI CODE FILE INDEX


@extends('../layouts.app')
@section('content')
<!-- START DATA -->
<div class="my-3 p-3 bg-body rounded shadow-sm">
<!-- FORM PENCARIAN -->
<div class="pb-3">
<form class="d-flex" action="" method="get">
<input class="form-control me-1" type="search" name="katakunci" value="{{ Request::get('katakunci') }}"
placeholder="Masukkan kata kunci" aria-label="Search">
<button class="btn btn-secondary" type="submit">Cari</button>
</form>
</div>
<!-- TOMBOL TAMBAH DATA -->
<div class="pb-3">
{{-- @@@@ diurl masukkan ini --}}
<a href='{{ url('/siswa/create') }}' class="btn btn-primary">+ Tambah Data</a>
</div>
<table class="table table-striped">
<thead>
<tr>
{{-- @@@@ tambah kolom --}}
<th class="col-md">No</th>
<th class="col-md">@sortablelink('NIS')</th>
<th class="col-md">Foto</th>
<th class="col-md">@sortablelink('Nama')</th>
<th class="col-md">@sortablelink('Jurusan')</th>
<th class="col-md">Tempat lahir</th>
<th class="col-md">Tanggal lahir</th>
<th class="col-md">Aksi</th>
</tr>
</thead>
<tbody>
{{-- @@@@ php untuk kolom no --}}
@php
$i = 1; //$data->firstitem();
@endphp
{{-- @@@@ gunakan foreach --}}
@foreach ($data as $item)
{{-- @@@@ masukkan <tr> nya --}}
<tr>
<td>{{ $i }}</td> {{-- @@ untuk nomer --}}
<td>{{ $item->nis }}</td>
<td>
{{-- @@@ untuk foto --}}
@if ($item->foto)
<img src="{{ asset('storage/' . $item->foto) }}" alt="foto" width="50"
height="50">
@else
Tidak ada
@endif
</td>
<td>{{ $item->nama }}</td>
<td>{{ $item->jurusan }}</td>
<td>{{ $item->tempat_lahir }}</td>
<td>{{ $item->tanggal_lahir }}</td>
<td>
{{-- @@@ tambahkan href --}}
<a href='{{ url('siswa/' . $item->nis . '/edit') }}' class="btn btn-warning btn-sm">Edit</a>
{{-- @@@@ tambahkan form untuk delete --}}
<form action="{{ url('siswa/' . $item->nis) }}" class="d-inline"
onsubmit="return confirm('Yakin akan menghapus data?')" method="POST">
@csrf
@method('DELETE')
<button type="submit" name="submit" class="btn btn-sm btn-danger">Del</button>
</form>
</td>
</tr>
{{-- @@@@ php untuk tambah no --}}
@php
$i++;
@endphp
@endforeach
</tbody>
</table>
{{-- @@@@ tambhkan halaman --}}
{{ $data->links() }}
</div>
<!-- AKHIR DATA -->
@endsection
ISI CODE FILE CREATE
@extends('../layouts.app')
@section('content')
{{-- @@@@ tambahkan action dan enctype --}}
<form action="{{url('siswa')}}" method='post' enctype="multipart/form-data">
{{-- @@@@tambahkan @csrf --}}
@csrf
<div class="my-3 p-3 bg-body rounded shadow-sm">
<div class="mb-3 row">
<label for="nis" class="col-sm-2 col-form-label">NIS</label>
<div class="col-sm-10">
{{-- @@@@ tambahkan value session --}}
<input type="number" class="form-control" name='nis' id="nis" value="{{Session::get('nis')}}">
</div>
</div>
<div class="mb-3 row">
<label for="nama" class="col-sm-2 col-form-label">Nama</label>
<div class="col-sm-10">
<input type="text" class="form-control" name='nama' id="nama" value="{{Session::get('nama')}}">
</div>
</div>
<div class="mb-3 row">
<label for="jurusan" class="col-sm-2 col-form-label">Jurusan</label>
<div class="col-sm-10">
<input type="text" class="form-control" name='jurusan' id="jurusan" value="{{Session::get('jurusan')}}">
</div>
</div>
<div class="mb-3 row">
<label for="tempat_lahir" class="col-sm-2 col-form-label">Tempat lahir</label>
<div class="col-sm-10">
<input type="text" class="form-control" name='tempat_lahir' id="tempat_lahir" value="{{Session::get('tempat_lahir')}}">
</div>
</div>
<div class="mb-3 row">
<label for="tanggal_lahir" class="col-sm-2 col-form-label">Tanggal lahir</label>
<div class="col-sm-10">
<input type="date" class="form-control" name='tanggal_lahir' id="tanggal_lahir" value="{{Session::get('tanggal_lahir')}}">
</div>
</div>
{{-- @@@@ tambahkan untuk fotonya --}}
<div class="mb-3 row">
<label for="foto" class="col-sm-2 col-form-label">foto</label>
<div class="col-sm-10">
<input type="file" class="form-control" name='foto' id="foto">
</div>
</div>
<div class="mb-3 row">
{{-- @@@@ tambahkan tombol kembali --}}
<a href="{{url('/siswa')}}" class="col btn btn-secondary">Kembali</a>
<div class="col-sm-10"><button type="submit" class="btn btn-primary" name="submit" style="float: right">SIMPAN</button></div>
</div>
</form>
</div>
<!-- AKHIR FORM -->
@endsection

ISI CODE FILE EDIT


@extends('../layouts.app')
@section('content')
{{-- @@@@ tambahkan action + nis dan enctype --}}
<form action="{{url('siswa/'.$data->nis)}}" method='post' enctype="multipart/form-data">
{{-- @@@@tambahkan @csrf --}}
@csrf
{{-- @@@@ tambahkan method put --}}
@method('PUT')
<div class="my-3 p-3 bg-body rounded shadow-sm">
<div class="mb-3 row">
<label for="nis" class="col-sm-2 col-form-label">NIS</label>
<div class="col-sm-10">
{{-- @@@@ tambahkan value --}}
<input type="number" class="form-control" name='nis' id="nis" value="{{$data->nis}}">
</div>
</div>
<div class="mb-3 row">
<label for="nama" class="col-sm-2 col-form-label">Nama</label>
<div class="col-sm-10">
<input type="text" class="form-control" name='nama' id="nama" value="{{$data->nama}}">
</div>
</div>
<div class="mb-3 row">
<label for="jurusan" class="col-sm-2 col-form-label">Jurusan</label>
<div class="col-sm-10">
<input type="text" class="form-control" name='jurusan' id="jurusan" value="{{$data->jurusan}}">
</div>
</div>
<div class="mb-3 row">
<label for="tempat_lahir" class="col-sm-2 col-form-label">Tempat lahir</label>
<div class="col-sm-10">
<input type="text" class="form-control" name='tempat_lahir' id="tempat_lahir" value="{{$data->tempat_lahir}}">
</div>
</div>
<div class="mb-3 row">
<label for="tanggal_lahir" class="col-sm-2 col-form-label">Tanggal lahir</label>
<div class="col-sm-10">
<input type="date" class="form-control" name='tanggal_lahir' id="tanggal_lahir" value="{{$data->tanggal_lahir}}">
</div>
</div>
{{-- @@@@ tambahkan untuk foto lamanya --}}
<div class="mb-3 row">
<label for="fotolama" class="col-sm-2 col-form-label">Foto sebelumnya</label>
{{-- @@@@ tambahkan ifnya --}}
@if ($data->foto)
<img src="{{asset('storage/'.$data->foto)}}" alt="foto" style="width: 100px; !importen">
@else
*Anda belum memasukkan foto
@endif
{{-- tambahkan input type hidden untuk mengirimkan fotolama ke controller --}}
<input type="hidden" name="fotolama" value="{{$data->foto}}">
</div>
{{-- @@@@ tambahkan input untuk foto barunta --}}
<div class="mb-3 row">
<label for="foto" class="col-sm-2 col-form-label">Masukkan foto baru</label>
<div class="col-sm-10">
<input type="file" class="form-control" name='foto' id="foto">
</div>
</div>
<div class="mb-3 row">
{{-- @@@@ tambahkan tombol kembali --}}
<a href="{{url('/siswa')}}" class="col btn btn-secondary">Kembali</a>
<div class="col-sm-10"><button type="submit" class="btn btn-primary" name="submit" style="float: right">SIMPAN</button></div>
</div>
</form>
</div>
<!-- AKHIR FORM -->
@endsection

ISI CODE FILE PESAN


@if (Session::has('success'))
<div class="pt-3">
<div class="alert alert-success">
{{Session::get('success')}}
</div>
</div>
@endif
@if ($errors->any())
<div class="pt-3">
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $item) <li>
{{$item}}</li>
@endforeach
</ul>
</div>
</div>
@endif
TAHAP TERAKHIR

Buka File RouteServiceProvider

saruakeun HOME = '/siswa';

Buka File AppServiceProvider


Isikeun CODE iyeu

<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Pagination\Paginator;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Paginator::useBootstrapFive();
}
}

Buka File Env terus saruakeun jeung na foto

Buka terminal ketikeun

php artisan storage:link


composer require kyslik/column-sortable
Buka File app.php di folder config

abuskeun code iyeu

atau tambahkeun kode eta didinya


<?php
use Illuminate\Support\Facades\Facade;
return [
/*
|--------------------------------------------------------------------------
| Application Name
|--------------------------------------------------------------------------
|
| This value is the name of your application. This value is used when the
| framework needs to place the application's name in a notification or
| any other location as required by the application or its packages.
|
*/
'name' => env('APP_NAME', 'Laravel'),
/*
|--------------------------------------------------------------------------
| Application Environment
|--------------------------------------------------------------------------
|
| This value determines the "environment" your application is currently
| running in. This may determine how you prefer to configure various
| services the application utilizes. Set this in your ".env" file.
|
*/
'env' => env('APP_ENV', 'production'),
/*
|--------------------------------------------------------------------------
| Application Debug Mode
|--------------------------------------------------------------------------
|
| When your application is in debug mode, detailed error messages with
| stack traces will be shown on every error that occurs within your
| application. If disabled, a simple generic error page is shown.
|
*/
'debug' => (bool) env('APP_DEBUG', false),
/*
|--------------------------------------------------------------------------
| Application URL
|--------------------------------------------------------------------------
|
| This URL is used by the console to properly generate URLs when using
| the Artisan command line tool. You should set this to the root of
| your application so that it is used when running Artisan tasks.
|
*/
'url' => env('APP_URL', 'http://localhost'),
'asset_url' => env('ASSET_URL'),
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
'timezone' => 'UTC',
/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by the translation service provider. You are free to set this value
| to any of the locales which will be supported by the application.
|
*/
'locale' => 'en',
/*
|--------------------------------------------------------------------------
| Application Fallback Locale
|--------------------------------------------------------------------------
|
| The fallback locale determines the locale to use when the current one
| is not available. You may change the value to correspond to any of
| the language folders that are provided through your application.
|
*/
'fallback_locale' => 'en',
/*
|--------------------------------------------------------------------------
| Faker Locale
|--------------------------------------------------------------------------
|
| This locale will be used by the Faker PHP library when generating fake
| data for your database seeds. For example, this will be used to get
| localized telephone numbers, street address information and more.
|
*/
'faker_locale' => 'en_US',
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| This key is used by the Illuminate encrypter service and should be set
| to a random, 32 character string, otherwise these encrypted strings
| will not be safe. Please do this before deploying an application!
|
*/
'key' => env('APP_KEY'),
'cipher' => 'AES-256-CBC',
/*
|--------------------------------------------------------------------------
| Maintenance Mode Driver
|--------------------------------------------------------------------------
|
| These configuration options determine the driver used to determine and
| manage Laravel's "maintenance mode" status. The "cache" driver will
| allow maintenance mode to be controlled across multiple machines.
|
| Supported drivers: "file", "cache"
|
*/
'maintenance' => [
'driver' => 'file',
// 'store' => 'redis',
],
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
|--------------------------------------------------------------------------
|
| The service providers listed here will be automatically loaded on the
| request to your application. Feel free to add your own services to
| this array to grant expanded functionality to your applications.
|
*/
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Auth\AuthServiceProvider::class,
Illuminate\Broadcasting\BroadcastServiceProvider::class,
Illuminate\Bus\BusServiceProvider::class,
Illuminate\Cache\CacheServiceProvider::class,
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
Illuminate\Cookie\CookieServiceProvider::class,
Illuminate\Database\DatabaseServiceProvider::class,
Illuminate\Encryption\EncryptionServiceProvider::class,
Illuminate\Filesystem\FilesystemServiceProvider::class,
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
Illuminate\Hashing\HashServiceProvider::class,
Illuminate\Mail\MailServiceProvider::class,
Illuminate\Notifications\NotificationServiceProvider::class,
Illuminate\Pagination\PaginationServiceProvider::class,
Illuminate\Pipeline\PipelineServiceProvider::class,
Illuminate\Queue\QueueServiceProvider::class,
Illuminate\Redis\RedisServiceProvider::class,
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
Illuminate\Session\SessionServiceProvider::class,
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
Kyslik\ColumnSortable\ColumnSortableServiceProvider::class,
/*
* Package Service Providers...
*/
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
],
/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| This array of class aliases will be registered when this application
| is started. However, feel free to register as many as you wish as
| the aliases are "lazy" loaded so they don't hinder performance.
|
*/
'aliases' => Facade::defaultAliases()->merge([
// 'ExampleClass' => App\Example\ExampleClass::class,
])->toArray(),
];
Buka Terminal Ketikeun iyeu

php artisan vendor:publish --


provider="Kyslik\ColumnSortable\ColumnSortableService
Provider" --tag="config"

BERES......

You might also like