60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Profile;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Throwable;
|
|
use App\Models\User;
|
|
|
|
class ProfileController extends Controller
|
|
{
|
|
|
|
public function profile(){
|
|
return view('user.profile.index', ['user' => Auth::user()]);
|
|
}
|
|
|
|
public function update(Request $request){
|
|
$nama_depan = $request->nama_depan;
|
|
$nama_belakang = $request->nama_belakang;
|
|
$nohp = $request->nohp;
|
|
$kode_kelurahan = $request->kelurahan;
|
|
$alamat = $request->alamat;
|
|
$nama_bank = $request->nama_bank;
|
|
$no_rek = $request->no_rek;
|
|
$foto_profile = '';
|
|
if($request->hasFile('foto_profile')){
|
|
$file = $request->file('foto_profile');
|
|
$extension = $file->getClientOriginalExtension();
|
|
$foto_profile = 'Foto-Profil-'.$nama_depan.' '.$nama_belakang.'.'.$extension;
|
|
$file->storeAs('storage/foto-profile/'.$foto_profile);
|
|
}
|
|
|
|
try{
|
|
DB::beginTransaction();
|
|
|
|
User::where('id', Auth::user()->id)->update([
|
|
'nama_depan' => $nama_depan,
|
|
'nama_belakang' => $nama_belakang,
|
|
'nohp' => $nohp,
|
|
'kode_kelurahan' => $kode_kelurahan,
|
|
'alamat' => $alamat,
|
|
'nama_bank' => $nama_bank,
|
|
'no_rek' => $no_rek,
|
|
'foto_profile' => $foto_profile,
|
|
]);
|
|
|
|
DB::commit();
|
|
}catch(Throwable $e){
|
|
DB::rollBack();
|
|
|
|
Log::error($e->getMessage());
|
|
|
|
return response()->json(['status' => false, 'message' => 'Terjadi Kesalahan pada sisi server']);
|
|
}
|
|
}
|
|
}
|