Posted by : Aulia Ihza H - 0089
Monday, June 28, 2021
1.Persiapan
- Menginstall PHP development environtment, contohnya XAMPP (apachefriends.org)
- Laravel 7 di Installation - Laravel - The PHP Framework For Web Artisans
- Membuka link petunjuk yang ada di Halo Bro: Membuat Halaman Web Pertama Dengan Laravel | ID Laravel (id-laravel.com)
- dan Membuat Form Registrasi Dengan Laravel | ID Laravel (id-laravel.com)
- Mount Folder Project di Windows Terminal
- Menginstall Composer (composer install)
- Menginstall Node Module (npm install && npm run dev)
- Membuat database bernama kreativ di MySQL XAMPP
- Di Windows terminal lagi
- Menjalankan migrasi database (php artisan migrate)
- Menjalankan Web di Lokal (php artisan serve)
2.Program Kreativ Company Profile
Setelah php artisan serve dijalankan secara default web dapat dilihat di http://127.0.0.1:8000/. Buat kontroller untuk CRUD dan view profile,menggunakan syntax
Jika ada crud -> php artisan make:controller [namakontroller] --resource --model=[namamodel]
Jika hanya view -> php artisan make:controller [namakontroller]
Jika model belum ada,akan dibuatkan sendiri sesuai dengan model yang kita definisikan.
Contoh Isi dari Controller untuk view halaman beranda,kreativ,karir, dan partner:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index(){
return view('pages.index');
}
public function kreativ(){
return view('pages.kreativ');
}
public function undercon(){
return view('pages.undercon');
}
public function karir(){
return view('pages.karir');
}
}
Contoh Isi dari Controller untuk CRUD halaman CRUD Reach Us:
<?php
namespace App\Http\Controllers;
use App\reachus;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class ReachusController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$reachsus = reachus::orderBy('created_at', 'desc')->get();
return view('reachus.index', compact('reachsus'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('reachus.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request,[
'name' => 'required',
'phone' => 'required',
'email' => 'required'
]);
//create req
$reachsus = new reachus;
$reachsus->name = $request->input('name');
$reachsus->company = $request->input('company');
$reachsus->phone = $request->input('phone');
$reachsus->email = $request->input('email');
$reachsus->time = $request->input('time');
$reachsus->date = $request->input('date');
$reachsus->desc = $request->input('desc');
$reachsus->save();
return redirect('reachus/create')->with('Success',"Permintaan Baru Berhasil Ditambah");
}
/**
* Display the specified resource.
*
* @param \App\reachus $reachus
* @return \Illuminate\Http\Response
*/
public function show(reachus $reachus)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\reachus $reachus
* @return \Illuminate\Http\Response
*/
public function edit(reachus $reachus)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\reachus $reachus
* @return \Illuminate\Http\Response
*/
public function update(Request $request, reachus $reachus)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\reachus $reachus
* @return \Illuminate\Http\Response
*/
public function destroy(reachus $reachus)
{
//
}
}
Untuk view dapat diatur pada Direktori-xampp\htdocs\[namaprogram]\resources\views
Untuk yang seputaran CRUD mewakili folder reachus
Untuk yang seputaran view non CRUD diwakili folder pages
Mengatur routing pada Direktori-xampp\htdocs\[namaprogram]\routes\web.php
...
Route::get('/', 'HomeController@index');
Route::get('/KreativMorePage', 'HomeController@kreativ');
Route::get('/Karir', 'HomeController@karir');
Route::get('/Undercon', 'HomeController@undercon');
Route::resource('reachus', 'ReachusController');
...
Isi model reachus di Direktori-xampp\htdocs\[namaprogram]\app\reachus.php yang digenerate sebelumnya
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class reachus extends Model
{
protected $table = 'reachus';
public $primaryKey = 'id_req';
}
Isi migrasi pada pembuatan tabel reachus (setelah diisi lakukan migrate kembali sesuai persiapan)
...
public function up()
{
Schema::create('reachus', function (Blueprint $table) {
$table->id("id_req");
$table->string('name');
$table->string('company');
$table->string('phone');
$table->string('email');
$table->time('time');
$table->date('date');
$table->longText('desc');
$table->timestamps();
});
}
public function down()
{
Schema::table('reachus', function (Blueprint $table) {
Schema::dropIfExists('reachus');
});
}
...
Link Github : aulkiller/kreativ (github.com)
Halaman Depan
Halaman Kreativ
Halaman Karir
Halaman Partner(Belum ada Partner)
Halaman ReachUs
Halaman ReachUs untuk view isi request