Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Alur

1. composer create-project --prefer-dist laravel/laravel blog "6.*"


2. php artisan storage:link
3. composer require laravel/ui "^1.0" --dev
4. php artisan ui vue --auth
5. npm install
6. npm run dev
7. buat middleware : php artisan make:middleware CekRole

$roles = $this->CekRoute($request->route());

$req_cek=$request->user();
//dd($req_cek);
if ($req_cek!=null) {
if( $request->user()->hasRole($roles) || !$roles)
{
return $next($request);
}
}

return redirect('/login')->with('gagal', 'Silahkan login kembali');


}
private function CekRoute($route)
{
$actions = $route->getAction();
return isset($actions['roles']) ? $actions['roles'] : null;
}

8. daftarkan middleware ke App/http/karnel.php : 'roles' => \App\Http\Middleware\


CekRole::class,
9. Edit middleware yang kita buat tadi yaitu CekRole
10. Setelah diganti, lakukan perintah : php artisan make:model Role –m

$table->increments('id');

$table->string('name');
$table->string('description');
$table->timestamps();
11. Atur model role

<?php

namespace App;
use Illuminate\Database\Eloquent\Model;

class Role extends Model


{
//
protected $table = 'roles';
protected $fillable = [];
}

12. Atur Model USER

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;

class User extends Authenticatable


{
use Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'username',
'password',
'role_id',
'status',
'detail_id',
'pic',
];

/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];

/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function role()
{
return $this->belongsTo('App\Role','role_id');
}

public function hasRole($roles)


{
$this->have_role = $this->getUserRole();

if(is_array($roles)){
foreach($roles as $need_role){
if($this->cekUserRole($need_role)) {
return true;
}
}
} else{
return $this->cekUserRole($roles);
}
return false;
}
private function getUserRole()
{
return $this->role()->getResults();
}

private function cekUserRole($role)


{
return (strtolower($role)==strtolower($this->have_role->name)) ? true :
false;
}
public function setPasswordAttribute($pass){
$this->attributes['password'] = Hash::make($pass);

}
public function data_tes()//menampilkan user dengan data tes yang diikuti
{
return $this->hasMany('App\peserta_tes');
}
}

13. Buat LoginController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
Use Auth;
use Illuminate\Support\Facades\Hash;
class LoginController extends Controller
{
public function masuk(Request $request)
{

// request()->validate([
// 'g-recaptcha-response' => 'required|captcha',
// ]);

$request->validate([
'username'=>['required'],
'password'=>['required']
]);
$username=$request->get('username');
$password=$request->get('password');
$user_cek=User::where('username','=',$username)->count();
if ($user_cek==0) {
return redirect('/login')->with('gagal', 'username Anda Tidak Terdaf
tar');
}else{
$user=User::where('username','=',$username)->first();
$p_asli=$password;
$p_hash=$user->password;
//dd(Hash::check($p_asli, $p_hash));
$cek=Hash::check($p_asli, $p_hash);
if ($cek) {
Auth::guard('web')->loginUsingId($user->id);
//dd($role->role);
if ($user->role_id==1) {
return redirect('/admin')->with('success', 'Berhasil M
asuk');
}else if ($user->role_id==2) {
return redirect('/siswa')->with('success', 'Berhasil Mas
uk');
}else if ($user->role_id==3) {
return redirect('/pendaftar')->with('success', 'Berhasil
Masuk');
}else if ($user->role_id==4) {
return redirect('/guru')->with('success', 'Berhasil Masu
k');
}else if ($user->role_id==5) {
return redirect('/sarpras')->with('success', 'Berhasil M
asuk');
}else if ($user->role_id==6) {
return redirect('/perpustakaan')->with('success', 'Berha
sil Masuk');
}else if ($user->role_id==7) {
return redirect('/bendahara')->with('success', 'Berhasil
Masuk');
}else{
return redirect('/login')->with('gagal', 'Anda Buka Siap
a Siapa!');
}
}else{
return redirect('/login')->with('gagal', 'Password Anda Sala
h');
}
}
}
public function keluar()
{
if (Auth::guard('web')->check()) {
# code...
Auth::guard('web','roles')->logout();
return redirect('/login');
}else{
return redirect('/login');
}
}
}
14. Buat controller setiap user

INSTAL DATA TABLE:

1. composer require yajra/laravel-datatables-oracle


2. Add Datatables Service Provider and Facade on config/app.php.

#config/app.php

'providers' => [

...

Yajra\Datatables\DatatablesServiceProvider::class,

'aliases' => [

...

'Datatables' => Yajra\Datatables\Facades\Datatables::class,

Next, enter the following command to publish the config file.

php artisan vendor:publish --provider="Yajra\DataTables\


DataTablesServiceProvider"

The above command will publish configuration file under config/datatables.php

INSTAL QR

1. composer require simplesoftwareio/simple-qrcode

2. Add Datatables Service Provider and Facade on config/app.php.

'providers' => [

....

SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class,

],
'aliases' => [

....

'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class,

],

Penggnaan di route

<?php

Route::get('qr-code-g', function () {

\QrCode::size(500)

->format('png')

->generate('ItSolutionStuff.com',
public_path('images/qrcode.png'));

return view('qrCode');

});

Penggunaan di Blade

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>
<body>

<div class="visible-print text-center">

<h1>Laravel 5.7 - QR Code Generator Example</h1>

{!! QrCode::size(250)->generate('ItSolutionStuff.com'); !!}

<p>example by ItSolutionStuf.com.</p>

</div>

</body>

</html>

Instal Import Export Excel

1. composer require maatwebsite/excel


2. Add Datatables Service Provider and Facade on config/app.php.

'providers' => [

....

Maatwebsite\Excel\ExcelServiceProvider::class,

],
'aliases' => [

....

'Excel' => Maatwebsite\Excel\Facades\Excel::class,

],

Query import

php artisan make:import UsersImport --model=User

Query Import

php artisan make:export UsersExport --model=User

Dokumentasi : https://morioh.com/p/b372edbd4284

Instalasi chat

1. composer require emotality/tawk-laravel

'providers' => [
...,
Emotality\TawkTo\TawkToServiceProvider::class,
];

...

'aliases' => [
...,
'TawkTo' => Emotality\TawkTo\Facades\TawkTo::class,
];

Jalankan :

php artisan vendor:publish --provider="Emotality\TawkTo\TawkToServiceProvider"

Masukan API Key Ke .ENV

TAWKTO_API_KEY=54f52bfdf7bcaa72719c6b7

git config credential.helper store


git config --global --unset credential.helper

You might also like