One Hat Cyber Team
Your IP :
10.30.1.1
Server IP :
103.148.201.5
Server :
Linux web-olt 5.15.0-156-generic #166-Ubuntu SMP Sat Aug 9 00:02:46 UTC 2025 x86_64
Server Software :
Apache/2.4.52 (Ubuntu)
PHP Version :
8.1.29
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
var
/
www
/
html
/
Compro-ISP
/
app
/
Http
/
Controllers
/
Edit File:
ClientController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Client; use Illuminate\Support\Str; use Illuminate\Support\Facades\Storage; class ClientController extends Controller { /** * Display a listing of the resource. */ public function index() { $data=Client::all(); return view('v.client.index',compact('data')); } /** * Show the form for creating a new resource. */ public function create() { return view('v.client.create'); } /** * Store a newly created resource in storage. */ public function store(Request $request) { $request->validate([ 'name' => 'required|string', 'images' => 'required|image|mimes:jpeg,png,jpg,gif,webp|max:10048', // max 2MB ]); // ✅ 2. Buat nama unik untuk gambar $originalName = pathinfo($request->file('images')->getClientOriginalName(), PATHINFO_FILENAME); $extension = $request->file('images')->getClientOriginalExtension(); // Sanitasi dan buat nama file unik $safeName = Str::slug($originalName); // contoh: "promo-hari-libur" $uniqueName = $safeName . '-' . uniqid() . '.' . $extension; // ✅ 3. Cek jika nama yang sama sudah ada (optional jika kamu simpan unik) if (Storage::disk('public')->exists('images/' . $uniqueName)) { return back()->withErrors(['images' => 'File dengan nama tersebut sudah ada.'])->withInput(); } // ✅ 4. Simpan gambar ke folder public/images $request->file('images')->storeAs('images', $uniqueName, 'public'); // ✅ 5. Simpan ke database Client::create([ 'name' => $request->name, 'images' => $uniqueName, // simpan path relatif ]); return redirect()->route('client.index')->with('success', 'Data Client berhasil ditambahkan.'); } /** * Display the specified resource. */ public function show(string $id) { } /** * Show the form for editing the specified resource. */ public function edit(string $id) { $data=Client::findOrFail($id); return view('v.client.edit',compact('data')); } /** * Update the specified resource in storage. */ public function update(Request $request, string $id) { $request->validate([ 'name' => 'required|string', 'images' => 'nullable|image|mimes:jpeg,png,jpg,gif,webp|max:10048', // optional di update ]); $home = Client::findOrFail($id); if ($request->hasFile('images')) { $image = $request->file('images'); // Buat nama unik dari gambar yang diupload $originalName = pathinfo($image->getClientOriginalName(), PATHINFO_FILENAME); $extension = $image->getClientOriginalExtension(); $safeName = Str::slug($originalName); $uniqueName = $safeName . '-' . uniqid() . '.' . $extension; // Cek jika file dengan nama tersebut sudah ada if (Storage::disk('public')->exists('images/' . $uniqueName)) { return back()->withErrors(['images' => 'File dengan nama tersebut sudah ada.'])->withInput(); } // Hapus gambar lama jika ada if ($home->images && Storage::exists('public/images/' . $home->images)) { Storage::delete('public/images/' . $home->images); } // Simpan gambar baru $image->storeAs('images', $uniqueName, 'public'); // Simpan nama file baru ke DB $home->images = $uniqueName; } // Update data lainnya $home->name = $request->name; $home->save(); return redirect()->route('client.index')->with('success', 'Data berhasil diupdate.'); } /** * Remove the specified resource from storage. */ public function destroy(string $id) { $data=Client::findOrFail($id); // Karena file sebenarnya ada di storage/app/public/images $imagePath = 'public/images/' . $data->images; if (Storage::exists($imagePath)) { Storage::delete($imagePath); } $data->delete(); return redirect()->route('client.index'); } }
Simpan