Commit 787cbfcc authored by Farhan Arif Setiawan's avatar Farhan Arif Setiawan
Browse files

first

parents
No related merge requests found
Showing with 1692 additions and 0 deletions
+1692 -0
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2
[docker-compose.yml]
indent_size = 4
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
* text=auto
*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php
/.github export-ignore
CHANGELOG.md export-ignore
.styleci.yml export-ignore
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.env.production
.phpunit.result.cache
Homestead.json
Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
/.fleet
/.idea
/.vscode
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
<p align="center">
<a href="https://travis-ci.org/laravel/framework"><img src="https://travis-ci.org/laravel/framework.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
</p>
## About Laravel
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](https://laravel.com/docs/routing).
- [Powerful dependency injection container](https://laravel.com/docs/container).
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
- [Robust background job processing](https://laravel.com/docs/queues).
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
Laravel is accessible, powerful, and provides tools required for large, robust applications.
## Learning Laravel
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) 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](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.
If you don't feel like reading, [Laracasts](https://laracasts.com) 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.
## Laravel Sponsors
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 [Patreon page](https://patreon.com/taylorotwell).
### Premium Partners
- **[Vehikl](https://vehikl.com/)**
- **[Tighten Co.](https://tighten.co)**
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
- **[64 Robots](https://64robots.com)**
- **[Cubet Techno Labs](https://cubettech.com)**
- **[Cyber-Duck](https://cyber-duck.co.uk)**
- **[Many](https://www.many.co.uk)**
- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)**
- **[DevSquad](https://devsquad.com)**
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
- **[OP.GG](https://op.gg)**
- **[WebReinvent](https://webreinvent.com/?utm_source=laravel&utm_medium=github&utm_campaign=patreon-sponsors)**
- **[Lendio](https://lendio.com)**
## Contributing
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
## Code of Conduct
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
## Security Vulnerabilities
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
## License
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
class Handler extends ExceptionHandler
{
/**
* A list of exception types with their corresponding custom log levels.
*
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
*/
protected $levels = [
//
];
/**
* A list of the exception types that are not reported.
*
* @var array<int, class-string<\Throwable>>
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];
/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
$this->reportable(function (Throwable $e) {
//
});
}
}
<?php
namespace App\Http\Controllers;
use App\Models\Agama44;
use App\Models\User;
use Illuminate\Http\Request;
class Admin44Controller extends Controller
{
public function dashboardPage44()
{
$user = User::where('role', 'user')->get();
$agama = Agama44::all();
return view('dashboard', ['data' => $user, 'agama' => $agama]);
}
public function detailPage44(Request $request)
{
$id = $request->id;
$user = User::find($id);
if (!$user) {
return redirect('/dashboard44')->with('error', 'User tidak ditemukan');
}
$agama = Agama44::all();
$detail = $user->detail;
$data = array_merge($user->toArray(), $detail->toArray());
return view('profile', ['user' => $data, 'agama' => $agama, 'is_preview' => true]);
}
public function updateUserStatus44(Request $request)
{
$id = $request->id;
$user = User::find($id);
if (!$user) {
return redirect('/dashboard44')->with('error', 'User tidak ditemukan');
}
$updateStatus = $user->update([
'is_active' => $user->is_active == 1 ? 0 : 1
]);
if ($updateStatus) {
return redirect('/dashboard44')->with('success', 'Status berhasil diubah');
} else {
return redirect('/dashboard44')->with('error', 'Status gagal diubah');
}
}
public function deleteUser44(Request $request)
{
$id = $request->id;
$user = User::find($id);
if (!$user) {
return redirect('/dashboard44')->with('error', 'User tidak ditemukan');
}
$deleteUser = $user->delete();
if ($deleteUser) {
return redirect('/dashboard44')->with('success', 'User berhasil dihapus');
} else {
return redirect('/dashboard44')->with('error', 'User gagal dihapus');
}
}
public function agamaPage44()
{
$agama = Agama44::all();
return view('agama', ['all_agama' => $agama]);
}
public function createAgama44(Request $request)
{
$request->validate([
'nama_agama' => 'required'
]);
$createAgama = Agama44::create([
'nama_agama' => $request->nama_agama
]);
if ($createAgama) {
return redirect('/agama44')->with('success', 'Agama berhasil ditambahkan');
} else {
return redirect('/agama44')->with('error', 'Agama gagal ditambahkan');
}
}
public function editAgamaPage44(Request $request)
{
$id = $request->id;
$agama = Agama44::find($id);
if (!$agama) {
return back()->with('error', 'Agama tidak ditemukan');
}
$all_agama = Agama44::all();
return view('agama', ['all_agama' => $all_agama, 'agama' => $agama]);
}
public function updateUserAgama44(Request $request)
{
$id = $request->id;
$user = User::find($id);
if (!$user) {
return redirect('/dashboard44')->with('error', 'User tidak ditemukan');
}
$request->validate([
'agama' => 'required|exists:agama44,id'
]);
$user->detail->id_agama = $request->agama;
$updateAgama = $user->detail->save();
if ($updateAgama) {
return redirect('/dashboard44')->with('success', 'Agama berhasil diubah');
} else {
return redirect('/dashboard44')->with('error', 'Agama gagal diubah');
}
}
public function deleteAgama44(Request $request)
{
$id = $request->id;
$agama = Agama44::find($id);
if (!$agama) {
return redirect('/agama44')->with('error', 'Agama tidak ditemukan');
}
$deleteAgama = $agama->delete();
if ($deleteAgama) {
return redirect('/agama44')->with('success', 'Agama berhasil dihapus');
} else {
return redirect('/agama44')->with('error', 'Agama gagal dihapus');
}
}
public function updateAgama44(Request $request)
{
$id = $request->id;
$agama = Agama44::find($id);
if (!$agama) {
return redirect('/agama44')->with('error', 'Agama tidak ditemukan');
}
$request->validate([
'nama_agama' => 'required'
]);
$updateAgama = $agama->update([
'nama_agama' => $request->nama_agama
]);
if ($updateAgama) {
return redirect('/agama44')->with('success', 'Agama berhasil diubah');
} else {
return redirect('/agama44')->with('error', 'Agama gagal diubah');
}
}
}
<?php
namespace App\Http\Controllers;
use App\Models\Agama44;
use Illuminate\Http\Request;
class Agama44Controller extends Controller
{
public function agamaPage44()
{
$agama = Agama44::all();
return view('agama', ['all_agama' => $agama]);
}
public function editAgamaPage44(Request $request)
{
$id = $request->id;
$agama = Agama44::find($id);
if (!$agama) {
return back()->with('error', 'Agama tidak ditemukan');
}
$all_agama = Agama44::all();
return view('agama', ['all_agama' => $all_agama, 'agama' => $agama]);
}
public function updateAgama44(Request $request)
{
$id = $request->id;
$agama = Agama44::find($id);
if (!$agama) {
return redirect('/agama44')->with('error', 'Agama tidak ditemukan');
}
$request->validate([
'nama_agama' => 'required'
]);
$updateAgama = $agama->update([
'nama_agama' => $request->nama_agama
]);
if ($updateAgama) {
return redirect('/agama44')->with('success', 'Agama berhasil diubah');
} else {
return redirect('/agama44')->with('error', 'Agama gagal diubah');
}
}
public function createAgama44(Request $request)
{
$request->validate([
'nama_agama' => 'required'
]);
$createAgama = Agama44::create([
'nama_agama' => $request->nama_agama
]);
if ($createAgama) {
return back()->with('success', 'Agama berhasil ditambahkan');
} else {
return back()->with('error', 'Agama gagal ditambahkan');
}
}
public function deleteAgama44(Request $request)
{
$id = $request->id;
$agama = Agama44::find($id);
if (!$agama) {
return redirect('/agama44')->with('error', 'Agama tidak ditemukan');
}
$deleteAgama = $agama->delete();
if ($deleteAgama) {
return redirect('/agama44')->with('success', 'Agama berhasil dihapus');
} else {
return redirect('/agama44')->with('error', 'Agama gagal dihapus');
}
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use App\Models\Agama44;
class Halo44Controller extends Controller
{
public function halo44()
{
$user = User::where('role', 'user')->get();
$agama = Agama44::all();
return view('welcome', ['data' => $user, 'agama' => $agama]);
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class Login44Controller extends Controller
{
public function login44(Request $request)
{
$request->validate([
'email' => 'required|email',
'password' => 'required|min:8'
]);
$isLogin = Auth::attempt($request->only('email', 'password'));
if ($isLogin) {
$user = Auth::user();
if ($user->role == "user" && $user->is_active == 1) {
return redirect('/dashboard44');
}
if ($user->role == "admin") {
return redirect('/dashboard44');
}
if ($user->role == "user" && $user->is_active == 0) {
Auth::logout();
return back()->with('error', 'Your account is not activated by Adminstrator');
}
}
return back()->with('error', 'Username or password not correct!');
}
}
<?php
namespace App\Http\Controllers;
use App\Models\Data44;
use App\Models\User;
use Illuminate\Http\Request;
class Register44Controller extends Controller
{
public function register44(Request $request)
{
$request->validate([
'name' => 'required',
'email' => 'required|email|unique:users44',
'password' => 'required|min:8',
'repassword' => 'required|same:password',
]);
$userData = $request->all();
$userData["password"] = bcrypt($request->password);
$userData["is_active"] = 0;
$user = new User();
$user->fill($userData);
$save = $user->save();
$detailUser = new Data44();
$detailUser->id_user = $user->id;
$detailUser->save();
if ($save && $detailUser) {
return redirect('/login44')->with('success', 'Register Success');
} else {
return back()->with('error', 'Register failed!');
}
}
}
<?php
namespace App\Http\Controllers;
use App\Models\User;
use App\Models\Agama44;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class User44Controller extends Controller
{
public function profilePage44()
{
$user = Auth::user();
$agama = Agama44::all();
$usersData = User::with("detail")->where("id", $user->id)->first();
$detail = $usersData->detail;
$all_data = array_merge($usersData->toArray(), $detail->toArray());
return view('profile', ['user' => $all_data, 'agama' => $agama, 'is_preview' => false]);
}
public function dashboardPage44()
{
$user = User::where('role', 'user')->get();
$agama = Agama44::all();
return view('dashboard', ['data' => $user, 'agama' => $agama]);
}
public function detailPage44(Request $request, $id)
{
$user = User::with('detail')->find($id);
if (!$user) {
return back()->with('error', 'User tidak ditemukan');
}
$agama = Agama44::all();
return view('profile', ['user' => $user, 'agama' => $agama, 'is_preview' => true]);
}
public function putUserDetail44(Request $request)
{
$user = Auth::user();
$request->validate([
'name' => 'required',
'email' => 'required|email|unique:users44,email,' . $user->id,
'alamat' => 'required',
'tempat_lahir' => 'required',
'tanggal_lahir' => 'required',
'id_agama' => 'required',
]);
$userData = User::find($user->id);
$detail = User::find($user->id)->detail;
$isAgamaValid = Agama44::find($request->id_agama);
if (!$isAgamaValid) {
return back()->with('error', 'Agama tidak valid');
}
$userData->name = $request->name;
$userData->email = $request->email;
$saveUser = $userData->save();
$detail->alamat = $request->alamat;
$detail->tempat_lahir = $request->tempat_lahir;
$detail->tanggal_lahir = $request->tanggal_lahir;
$detail->id_agama = $request->id_agama;
$detail->umur = date_diff(date_create($request->tanggal_lahir), date_create('now'))->y;
$saveDetail = $detail->save();
if ($saveUser && $saveDetail) {
return back()->with('success', 'Update profile berhasil');
} else {
return back()->with('error', 'Update profile gagal');
}
}
public function putUserStatus44(Request $request, $id)
{
$user = User::find($id);
if (!$user) {
return back()->with('error', 'User tidak ditemukan');
}
$updateStatus = $user->update([
'is_active' => $user->is_active == 1 ? 0 : 1
]);
if ($updateStatus) {
return back()->with('success', 'Status berhasil diubah');
} else {
return back()->with('error', 'Status gagal diubah');
}
}
public function putUserAgama44(Request $request, $id)
{
$user = User::with('detail')->find($id);
if (!$user) {
return back()->with('error', 'User tidak ditemukan');
}
$request->validate([
'agama' => 'required|exists:agama44,id'
]);
$user->detail->update([
'id_agama' => $request->agama
]);
$updateAgama = $user->detail->save();
if ($updateAgama) {
return back()->with('success', 'Agama berhasil diubah');
} else {
return back()->with('error', 'Agama gagal diubah');
}
}
public function putUserPhotoKTP44()
{
$user = Auth::user();
$detail = User::find($user->id)->detail;
Validator::make(request()->all(), [
'photoKTP' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
])->validate();
if ($detail->foto_ktp != "foto_ktp.png") {
if (file_exists(public_path('photo/' . $detail->foto_ktp))) {
unlink(public_path('photo/' . $detail->foto_ktp));
}
}
$file = request()->file('photoKTP');
$fileName = time() . '.' . $file->getClientOriginalExtension();
$file->move(public_path('photo/'), $fileName);
$detail->foto_ktp = $fileName;
$savePhoto = $detail->save();
if ($savePhoto) {
return back()->with('success', 'Upload foto ktp berhasil');
} else {
return back()->with('error', 'Upload foto ktp gagal');
}
}
public function putUserPhoto44(Request $request)
{
$user = Auth::user();
$detail = User::find($user->id);
Validator::make(request()->all(), [
'photoProfil' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
])->validate();
if ($detail->foto != "foto.png") {
if (file_exists(public_path('photo/' . $detail->foto))) {
unlink(public_path('photo/' . $detail->foto));
}
}
$file = request()->file('photoProfil');
$fileName = time() . '.' . $file->getClientOriginalExtension();
$file->move(public_path('photo/'), $fileName);
$detail->foto = $fileName;
$savePhoto = $detail->save();
if ($savePhoto) {
return back()->with('success', 'Upload foto profil berhasil');
} else {
return back()->with('error', 'Upload foto profil gagal');
}
}
public function putUserPassword44(Request $request)
{
$user = Auth::user();
$request->validate([
'old_password' => 'required|min:8',
'password' => 'required|min:8',
'repassword' => 'required|same:password',
]);
$userData = User::find($user->id);
if (!Hash::check($request->old_password, $userData->password)) {
return back()->with('error', 'Password lama tidak sesuai');
}
$userData->password = bcrypt($request->password);
$saveUser = $userData->save();
if ($saveUser) {
return back()->with('success', 'Update password berhasil');
} else {
return back()->with('error', 'Update password gagal');
}
}
public function logout44()
{
Auth::logout();
return redirect('/login44');
}
}
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Http\Resources\FormatApi;
use App\Models\Agama44;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class Agama44Controller extends Controller
{
public function getAgama44(Request $request)
{
$agama = Agama44::all();
return new FormatApi(true, 'Berhasil mendapatkan data agama', $agama);
}
public function getDetailAgama44(Request $request, $id)
{
$agama = Agama44::find($id);
if (!$agama) {
return new FormatApi(false, 'Agama tidak ditemukan', null);
}
return new FormatApi(true, 'Berhasil mendapatkan data agama', $agama);
}
public function postAgama44(Request $request)
{
$validator = Validator::make($request->all(), [
'nama_agama' => 'required',
]);
if ($validator->fails()) {
return new FormatApi(false, 'Validasi gagal', $validator->errors()->all());
}
$createUser = Agama44::create([
'nama_agama' => $request->nama_agama,
]);
if ($createUser) {
return new FormatApi(true, 'Berhasil menambahkan data agama', $createUser);
} else {
return new FormatApi(false, 'Gagal menambahkan data agama', null);
}
}
public function putAgama44(Request $request, $id)
{
$agama = Agama44::find($id);
if (!$agama) {
return new FormatApi(false, 'Agama tidak ditemukan', null);
}
$validator = Validator::make($request->all(), [
'nama_agama' => 'required',
]);
if ($validator->fails()) {
return new FormatApi(false, 'Validasi gagal', $validator->errors()->all());
}
$agama->update([
'nama_agama' => $request->nama_agama,
]);
return new FormatApi(true, 'Berhasil mengubah data agama', null);
}
public function deleteAgama44(Request $request, $id)
{
$agama = Agama44::find($id);
if (!$agama) {
return new FormatApi(false, 'Agama tidak ditemukan', null);
}
$agama->delete();
return new FormatApi(true, 'Berhasil menghapus data agama', null);
}
}
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Http\Resources\FormatApi;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Hash;
class User44Controller extends Controller
{
public function getUsers44()
{
$user = User::with('detail')->where('role', 'user')->get();
return new FormatApi(true, 'Berhasil mendapatkan data user', $user);
}
public function getUserDetail44(Request $request, $id)
{
$user = User::with('detail')->find($id);
if (!$user) {
return new FormatApi(false, 'User tidak ditemukan', null);
}
return new FormatApi(true, 'Berhasil mendapatkan data user', $user);
}
public function putUserDetail44(Request $request, $id)
{
$user = User::with('detail')->find($id);
if (!$user) {
return new FormatApi(false, 'User tidak ditemukan', null);
}
$validator = Validator::make($request->all(), [
'name' => 'required',
'email' => 'required|email|unique:users44,email,' . $user->id,
'alamat' => 'required',
'tempat_lahir' => 'required',
'tanggal_lahir' => 'required',
'id_agama' => 'required',
]);
if ($validator->fails()) {
return new FormatApi(false, 'Validasi gagal', $validator->errors()->all());
}
$updateUser = $user->update([
'name' => $request->name,
'email' => $request->email,
]);
$updateDetail = $user->detail->update([
'alamat' => $request->alamat,
'tempat_lahir' => $request->tempat_lahir,
'tanggal_lahir' => $request->tanggal_lahir,
'id_agama' => $request->id_agama,
]);
if ($updateUser && $updateDetail) {
return new FormatApi(true, 'Berhasil mengubah data user', null);
} else {
return new FormatApi(false, 'Gagal mengubah data user', null);
}
}
public function putUserPhoto44(Request $request, $id)
{
$user = User::with('detail')->find($id);
if (!$user) {
return new FormatApi(false, 'User tidak ditemukan', null);
}
$validator = Validator::make($request->all(), [
'photoProfil' => 'required',
]);
$fileName = $request->photoProfil;
if ($validator->fails()) {
return new FormatApi(false, 'Validasi gagal', $validator->errors()->all());
}
if ($user->foto != "foto.png") {
if (file_exists(public_path('images/' . $user->foto))) {
unlink(public_path('photo/' . $user->foto));
}
}
if (file_exists(public_path('tmp/' . $fileName))) {
$updatePhoto = $user->update([
'foto' => $fileName,
]);
rename(public_path('tmp/' . $fileName), public_path('photo/' . $fileName));
if ($updatePhoto) {
return new FormatApi(true, 'Berhasil mengubah foto profil user', null);
} else {
return new FormatApi(false, 'Gagal mengubah foto profil user', null);
}
} else {
return new FormatApi(false, 'File tidak ditemukan', null);
}
}
public function putUserPhotoKTP44(Request $request, $id)
{
$user = User::with('detail')->find($id);
if (!$user) {
return new FormatApi(false, 'User tidak ditemukan', null);
}
$validator = Validator::make($request->all(), [
'photoKTP' => 'required',
]);
$fileName = $request->photoKTP;
if ($validator->fails()) {
return new FormatApi(false, 'Validasi gagal', $validator->errors()->all());
}
if ($user->foto != "foto_ktp.png") {
if (file_exists(public_path('images/' . $user->detail->foto_ktp))) {
unlink(public_path('photo/' . $user->detail->foto_ktp));
}
}
if (file_exists(public_path('tmp/' . $fileName))) {
$updatePhoto = $user->detail->update([
'foto_ktp' => $fileName,
]);
rename(public_path('tmp/' . $fileName), public_path('photo/' . $fileName));
if ($updatePhoto) {
return new FormatApi(true, 'Berhasil mengubah foto profil user', null);
} else {
return new FormatApi(false, 'Gagal mengubah foto profil user', null);
}
} else {
return new FormatApi(false, 'File tidak ditemukan', null);
}
}
public function putUserPassword44(Request $request, $id)
{
$user = User::with('detail')->find($id);
if (!$user) {
return new FormatApi(false, 'User tidak ditemukan', null);
}
$validator = Validator::make($request->all(), [
'old_password' => 'required|min:8',
'password' => 'required|min:8',
'repassword' => 'required|same:password',
]);
if ($validator->fails()) {
return new FormatApi(false, 'Validasi gagal', $validator->errors()->all());
}
if (!Hash::check($request->old_password, $user->password)) {
return new FormatApi(false, 'Password lama tidak sesuai', null);
}
$updatePassword = $user->update([
'password' => bcrypt($request->password),
]);
if ($updatePassword) {
return new FormatApi(true, 'Berhasil mengubah password user', null);
} else {
return new FormatApi(false, 'Gagal mengubah password user', null);
}
}
public function putUserStatus44(Request $request, $id)
{
$user = User::with('detail')->find($id);
if (!$user) {
return new FormatApi(false, 'User tidak ditemukan', null);
}
$validator = Validator::make($request->all(), [
'is_active' => 'required|boolean',
]);
if ($validator->fails()) {
return new FormatApi(false, 'Validasi gagal', $validator->errors()->all());
}
$updateStatus = $user->update([
'is_active' => $request->is_active,
]);
if ($updateStatus) {
return new FormatApi(true, 'Berhasil mengubah status user', null);
} else {
return new FormatApi(false, 'Gagal mengubah status user', null);
}
}
public function putUserAgama44(Request $request, $id)
{
$user = User::with('detail')->find($id);
if (!$user) {
return new FormatApi(false, 'User tidak ditemukan', null);
}
$validator = Validator::make($request->all(), [
'id_agama' => 'required|exists:agama44,id',
]);
if ($validator->fails()) {
return new FormatApi(false, 'Validasi gagal', $validator->errors()->all());
}
$updateAgama = $user->detail->update([
'id_agama' => $request->id_agama,
]);
if ($updateAgama) {
return new FormatApi(true, 'Berhasil mengubah agama user', null);
} else {
return new FormatApi(false, 'Gagal mengubah agama user', null);
}
}
public function deleteUser44($id)
{
$user = User::with('detail')->find($id);
if (!$user) {
return new FormatApi(false, 'User tidak ditemukan', null);
}
if ($user->foto != "foto.png") {
if (file_exists(public_path('images/' . $user->foto))) {
unlink(public_path('photo/' . $user->foto));
}
}
if ($user->detail->foto_ktp != "foto_ktp.png") {
if (file_exists(public_path('images/' . $user->detail->foto_ktp))) {
unlink
(public_path('photo/' . $user->detail->foto_ktp));
}
}
}
}
<?php
namespace App\Http\Controllers\apiclient;
use App\Http\Controllers\Controller;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
class Agama62Controller extends Controller
{
public function agamaPage62()
{
$client = new Client();
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$getAgama = $client->request('GET', "{$API_URL}/agama62")->getBody()->getContents();
$agama = json_decode($getAgama, true)['data'];
return view('agama', ['all_agama' => $agama, 'Use_API' => true]);
}
public function editAgamaPage62(Request $request, $id)
{
$client = new Client();
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$getAgama = $client->request('GET', "{$API_URL}/agama62/{$id}")->getBody()->getContents();
$agama = json_decode($getAgama, true)['data'];
if (!$agama) {
return back()->with('error', 'Agama tidak ditemukan');
}
$getAllAgama = $client->request('GET', "{$API_URL}/agama62")->getBody()->getContents();
$all_agama = json_decode($getAllAgama, true)['data'];
return view('agama', ['all_agama' => $all_agama, 'agama' => $agama, 'Use_API' => true]);
}
public function createAgama62(Request $request)
{
$client = new Client();
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$getAllAgama = $client->request('POST', "{$API_URL}/agama62", [
'json' => [
'nama_agama' => $request->nama_agama,
]
])->getBody()->getContents();
$response = json_decode($getAllAgama, true)['status'];
if ($response != true) {
return back()->with('error', 'Agama gagal ditambahkan');
}
return back()->with('success', 'Agama berhasil ditambahkan');
}
public function updateAgama62(Request $request, $id)
{
$client = new Client();
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$getAllAgama = $client->request('PUT', "{$API_URL}/agama62/{$id}", [
'json' => [
'nama_agama' => $request->nama_agama,
]
])->getBody()->getContents();
$response = json_decode($getAllAgama, true)['status'];
if ($response != true) {
return back()->with('error', 'Agama gagal diubah');
}
return back()->with('success', 'Agama berhasil diubah');
}
public function deleteAgama62(Request $request, $id)
{
$client = new Client();
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$getAllAgama = $client->request('DELETE', "{$API_URL}/agama62/{$id}")->getBody()->getContents();
$response = json_decode($getAllAgama, true)['status'];
return back()->with('success', 'Agama berhasil dihapus');
}
}
<?php
namespace App\Http\Controllers\apiclient;
use App\Http\Controllers\Controller;
use App\Models\User;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class User62Controller extends Controller
{
public function dashboardPage62()
{
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$client = new Client();
$getUser = $client->request('GET', "{$API_URL}/user62")->getBody()->getContents();
$getAgama = $client->request('GET', "{$API_URL}/agama62")->getBody()->getContents();
$user = json_decode($getUser, true)['data'];
$agama = json_decode($getAgama, true)['data'];
return view('dashboard', ['data' => $user, 'agama' => $agama, 'Use_API' => true]);
}
public function profilePage62()
{
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$client = new Client();
$user = Auth::user();
$getUser = $client->request('GET', "{$API_URL}/user62/{$user->id}")->getBody()->getContents();
$getAgama = $client->request('GET', "{$API_URL}/agama62")->getBody()->getContents();
$user = json_decode($getUser, true)['data'];
$agama = json_decode($getAgama, true)['data'];
return view('profile', ['user' => $user, 'agama' => $agama, 'is_preview' => false, 'Use_API' => true]);
}
public function detailPage62(Request $request, $id)
{
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$client = new Client();
$getUser = $client->request('GET', "{$API_URL}/user62/{$id}")->getBody()->getContents();
$user = json_decode($getUser, true)['data'];
if (!$user) {
return redirect('dashboard')->with('error', 'User tidak ditemukan');
}
$getAgama = $client->request('GET', "{$API_URL}/agama62")->getBody()->getContents();
$agama = json_decode($getAgama, true)['data'];
return view('profile', ['user' => $user, 'agama' => $agama, 'is_preview' => true]);
}
public function putUserDetail62(Request $request)
{
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$client = new Client();
$user = Auth::user();
$validator = Validator::make($request->all(), [
'name' => 'required',
'email' => 'required|email|unique:users62,email,' . $user->id,
'alamat' => 'required',
'tempat_lahir' => 'required',
'tanggal_lahir' => 'required',
'id_agama' => 'required',
]);
if ($validator->fails()) {
return back()->with('error', 'User gagal diubah');
}
$putUser = $client->request('PUT', "{$API_URL}/user62/{$user->id}", [
'json' => [
'name' => $request->name,
'email' => $request->email,
'alamat' => $request->alamat,
'tempat_lahir' => $request->tempat_lahir,
'tanggal_lahir' => $request->tanggal_lahir,
'id_agama' => $request->id_agama,
]
])->getBody()->getContents();
$response = json_decode($putUser, true)['status'];
if ($response != true) {
return back()->with('error', 'User gagal diubah');
}
return back()->with('success', 'User berhasil diubah');
}
public function putUserAgama62(Request $request, $id)
{
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$client = new Client();
$validator = Validator::make($request->all(), [
'agama' => 'required',
]);
if ($validator->fails()) {
return back()->with('error', 'User gagal diubah');
}
$putUserAgama = $client->request('PUT', "{$API_URL}/user62/{$id}/agama", [
'json' => [
'id_agama' => $request->agama,
]
])->getBody()->getContents();
$response = json_decode($putUserAgama, true)['status'];
if ($response != true) {
return back()->with('error', 'User gagal diubah');
}
return back()->with('success', 'User berhasil diubah');
}
public function putUserStatus62(Request $request, $id)
{
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$client = new Client();
$user = User::find($id);
$putUserStatus = $client->request('PUT', "{$API_URL}/user62/{$id}/status", [
'json' => [
'is_active' => $user->is_active == 1 ? 0 : 1,
]
])->getBody()->getContents();
$response = json_decode($putUserStatus, true)['status'];
if ($response != true) {
return back()->with('error', 'User gagal diubah');
}
return back()->with('success', 'User berhasil diubah');
}
public function putUserPassword62(Request $request)
{
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$client = new Client();
$user = Auth::user();
$validator = Validator::make($request->all(), [
'old_password' => 'required|min:8',
'password' => 'required|min:8',
'repassword' => 'required|same:password',
]);
if ($validator->fails()) {
return back()->with('error', 'Pastikan semua field terisi dengan benar');
}
$putUserPassword = $client->request('PUT', "{$API_URL}/user62/{$user->id}/password", [
'json' => [
'old_password' => $request->old_password,
'password' => $request->password,
'repassword' => $request->repassword,
]
])->getBody()->getContents();
$response = json_decode($putUserPassword, true)['status'];
if ($response != true) {
return back()->with('error', 'Password gagal diubah');
}
return back()->with('success', 'Password berhasil diubah');
}
public function putUserPhoto62(Request $request)
{
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$client = new Client();
$id = Auth::user()->id;
$validator = Validator::make($request->all(), [
'photoProfil' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
if ($validator->fails()) {
return back()->with('error', 'Pastikan semua field terisi dengan benar');
}
$photo = $request->file('photoProfil');
$fileNameTmp = time() . $photo->getClientOriginalName();
$photo->move(public_path('tmp'), $fileNameTmp);
$putUserPhoto = $client->request('PUT', "{$API_URL}/user62/{$id}/photo", [
'headers' => [
'Accept' => 'application/json',
],
'json' => [
'photoProfil' => $fileNameTmp,
]
])->getBody()->getContents();
$response = json_decode($putUserPhoto, true)['status'];
if ($response != true) {
return back()->with('error', 'Photo gagal diubah');
}
return back()->with('success', 'Photo berhasil diubah');
}
public function putUserPhotoKTP62(Request $request)
{
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$client = new Client();
$id = Auth::user()->id;
$validator = Validator::make($request->all(), [
'photoKTP' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
if ($validator->fails()) {
return back()->with('error', 'Pastikan semua field terisi dengan benar');
}
$photo = $request->file('photoKTP');
$fileNameTmp = time() . $photo->getClientOriginalName();
$photo->move(public_path('tmp'), $fileNameTmp);
$putUserPhoto = $client->request('PUT', "{$API_URL}/user62/{$id}/photoKTP", [
'headers' => [
'Accept' => 'application/json',
],
'json' => [
'photoKTP' => $fileNameTmp,
]
])->getBody()->getContents();
$response = json_decode($putUserPhoto, true)['status'];
if ($response != true) {
return back()->with('error', 'photoKTP gagal diubah');
}
return back()->with('success', 'photoKTP berhasil diubah');
}
public function deleteUser62($id)
{
$API_URL = env('API_URL', "http://localhost/BackEnd/UAS-Backend/public/api");
$client = new Client();
$deleteUser = $client->request('DELETE', "{$API_URL}/user62/{$id}", [
'headers' => [
'Accept' => 'application/json',
],
])->getBody()->getContents();
$response = json_decode($deleteUser, true)['status'];
if ($response != true) {
return back()->with('error', 'User gagal dihapus');
}
return back()->with('success', 'User berhasil dihapus');
}
}
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array<int, class-string|string>
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Illuminate\Http\Middleware\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
/**
* The application's route middleware groups.
*
* @var array<string, array<int, class-string|string>>
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array<string, class-string|string>
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'isUser' => \App\Http\Middleware\IsUser::class,
'isAdmin' => \App\Http\Middleware\IsAdmin::class,
'isLogin' => \App\Http\Middleware\IsLogin::class,
'isNotLogin' => \App\Http\Middleware\IsNotLogin::class,
];
}
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment