refactor: part one
This commit is contained in:
parent
c622a9b069
commit
5c972770a6
@ -11,43 +11,39 @@
|
||||
|
||||
class AiringProofThemeController extends Controller
|
||||
{
|
||||
private function checkExistedData($slug, $isSoftDeleted = false)
|
||||
{
|
||||
$query = AiringProofTheme::withTrashed()->where('slug', $slug);
|
||||
|
||||
if($isSoftDeleted){
|
||||
$query->whereNotNull('deleted_at');
|
||||
}
|
||||
|
||||
return $query->first();
|
||||
}
|
||||
|
||||
public function index(){
|
||||
return view('dashboard.airing-proof-themes.index', [
|
||||
'title' => "Tema Bukti Tayang"
|
||||
'title' => "Data Tema Bukti Tayang"
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(){
|
||||
return view('dashboard.airing-proof-themes.create', [
|
||||
'title' => "Tambah Tema Bukti Tayang"
|
||||
'title' => "Buat Tema Bukti Tayang Baru"
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(AiringProofThemeRequest $request){
|
||||
$validatedData = $request->validated();
|
||||
|
||||
if($this->checkExistedData($validatedData['slug'], true)){
|
||||
try{
|
||||
$existing = AiringProofTheme::withTrashed()
|
||||
->where('slug', $validatedData['slug'])
|
||||
->first();
|
||||
|
||||
if ($existing?->trashed()) {
|
||||
return redirect()->back()->with('data-exists', $validatedData['slug']);
|
||||
}elseif($this->checkExistedData($validatedData['slug'])){
|
||||
return redirect()->back()->with('failed-status', 'Tema dengan nama dan tahun tersebut sudah ada.');
|
||||
} elseif ($existing) {
|
||||
return redirect()->back()
|
||||
->with('failed-status', 'Tema dengan nama dan tahun tersebut sudah ada.');
|
||||
}
|
||||
|
||||
try{
|
||||
AiringProofTheme::create($validatedData);
|
||||
return redirect()->back()->with('success-status', 'Berhasil menambahkan tema bukti tayang.');
|
||||
$createdAiringProofTheme = AiringProofTheme::create($validatedData);
|
||||
|
||||
return redirect()->route('dashboard.airing.proof.themes.index')->with('success-status', 'Berhasil membuat tema bukti tayang baru.')
|
||||
->with('new_data', encrypt_id($createdAiringProofTheme->id));
|
||||
}catch(\Exception $e){
|
||||
return redirect()->back()->with('failed-status', 'Gagal menambahkan tema bukti tayang.');
|
||||
return redirect()->back()->with('failed-status', 'Gagal membuat tema bukti tayang baru.');
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +62,8 @@ public function update(AiringProofThemeRequest $request, $id){
|
||||
try{
|
||||
$airingProofTheme = AiringProofTheme::findOrFail(decrypt_id($id));
|
||||
$airingProofTheme->update($validatedData);
|
||||
return redirect()->back()->with('success-status', 'Berhasil mengubah tema bukti tayang.');
|
||||
|
||||
return redirect()->route('dashboard.airing.proof.themes.show', ['id' => encrypt_id($airingProofTheme->id)])->with('success-status', 'Berhasil mengubah tema bukti tayang.');
|
||||
}catch(\Exception $e){
|
||||
return redirect()->back()->with('failed-status', 'Gagal mengubah tema bukti tayang.');
|
||||
}
|
||||
@ -94,6 +91,8 @@ public function destroy($id){
|
||||
|
||||
public function restore($slug)
|
||||
{
|
||||
|
||||
try{
|
||||
$airingProofTheme = AiringProofTheme::withTrashed()
|
||||
->where('slug', $slug)
|
||||
->first();
|
||||
@ -104,10 +103,13 @@ public function restore($slug)
|
||||
|
||||
if (filled($airingProofTheme->deleted_at)) {
|
||||
$airingProofTheme->restore();
|
||||
return redirect()->back()->with('success-status', 'Tema berhasil dipulihkan.');
|
||||
return redirect()->route('dashboard.airing.proof.themes.index')->with('success-status', 'Tema berhasil dipulihkan.');
|
||||
}
|
||||
|
||||
return redirect()->back()->with('info-status', 'Tema sudah aktif.');
|
||||
}catch(\Exception $e){
|
||||
return redirect()->back()->with('failed-status', 'Proses pemulihan gagal.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -9,16 +9,19 @@
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AnnouncementController extends Controller
|
||||
{
|
||||
public function index(Request $request){
|
||||
|
||||
$category = $request->input('category', 'general');
|
||||
|
||||
$data = [
|
||||
'title' => 'Pengumuman',
|
||||
'category' => $category
|
||||
];
|
||||
|
||||
if(is_role(['1'])){
|
||||
return view('dashboard.announcements.index', $data);
|
||||
}else if(is_role(['3'])){
|
||||
@ -28,34 +31,44 @@ public function index(Request $request){
|
||||
|
||||
public function create(){
|
||||
return view('dashboard.announcements.create', [
|
||||
'title' => 'Tambah Pengumuman',
|
||||
'title' => 'Buat Pengumuman Baru',
|
||||
'users' => User::all()
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(AnnouncementRequest $request){
|
||||
$validatedData = $request->validated();
|
||||
$validatedData['enhancer_id'] = Auth::id();
|
||||
|
||||
try{
|
||||
|
||||
if($request->hasFile('attachment')){
|
||||
$validatedData['attachment'] = store_file($validatedData['attachment'], '/uploads/announcements')['randomFileName'];
|
||||
}
|
||||
|
||||
$announcement = DB::transaction(function() use ($validatedData){
|
||||
$announcement = Announcement::create($validatedData);
|
||||
$announcement->users()->attach($validatedData['user_ids']);
|
||||
|
||||
if ($announcement->users()->count() > 0) {
|
||||
return redirect()->route('dashboard.announcements.index')->with('success-status', 'Berhasil membuat pengumuman.');
|
||||
} else {
|
||||
return redirect()->back()->with('failed-status', 'Gagal membuat pengumuman');
|
||||
|
||||
if($announcement->users()->count() < 1){
|
||||
throw new \Exception("Data tidak valid.");
|
||||
}
|
||||
|
||||
return $announcement;
|
||||
});
|
||||
|
||||
}catch(\Exception $e){
|
||||
return redirect()->back()->with('failed-status', 'Gagal membuat pengumuman baru');
|
||||
}
|
||||
|
||||
return redirect()->route('dashboard.announcements.index')->with('success-status', 'Berhasil membuat pengumuman baru.')->with('new_data', encrypt_id($announcement->id));
|
||||
}
|
||||
|
||||
public function edit($id){
|
||||
$announcement = Announcement::with(['users'])->findOrFail(decrypt_id($id));
|
||||
|
||||
return view('dashboard.announcements.edit', [
|
||||
'title' => 'Tambah Pengumuman',
|
||||
'title' => 'Ubah Pengumuman',
|
||||
'announcement' => $announcement,
|
||||
'users' => User::all(),
|
||||
'selectedUsersIds' => $announcement->users->pluck('id')->toArray()
|
||||
@ -64,10 +77,12 @@ public function edit($id){
|
||||
|
||||
public function update(AnnouncementRequest $request, $id){
|
||||
$validatedData = $request->validated();
|
||||
$validatedData['enhancer_id'] = Auth::id();
|
||||
|
||||
try{
|
||||
|
||||
$announcement = Announcement::with(['users'])->findOrFail(decrypt_id($id));
|
||||
|
||||
DB::transaction(function () use($request, $validatedData, $announcement){
|
||||
if($request->hasFile('attachment')){
|
||||
$validatedData['attachment'] = store_file($validatedData['attachment'], '/uploads/announcements')['randomFileName'];
|
||||
delete_file('uploads/announcements/'.$announcement->attachment);
|
||||
@ -84,11 +99,12 @@ public function update(AnnouncementRequest $request, $id){
|
||||
|
||||
$announcement->users()->sync($mediaData);
|
||||
}
|
||||
});
|
||||
|
||||
if ($announcement->users()->count() > 0) {
|
||||
return redirect()->back()->with('success-status', 'Berhasil mengubah pengumuman.');
|
||||
} else {
|
||||
return redirect()->back()->with('failed-status', 'Gagal mengubah pengumuman');
|
||||
}catch(\Exception $e){
|
||||
|
||||
return redirect()->back()->with('failed-status', 'Gagal mengubah pengumuman.');
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,24 +119,6 @@ public function show($id){
|
||||
]);
|
||||
}
|
||||
|
||||
public function read($id){
|
||||
$announcement = Announcement::with(['users'])->findOrFail(decrypt_id($id));
|
||||
|
||||
$userid = Auth::user()->id;
|
||||
if(!in_array($userid, $announcement->users->pluck('id')->toArray())){
|
||||
abort(404, "Pengumuman tidak ditemukan.");
|
||||
}
|
||||
|
||||
$announcement->users()->updateExistingPivot($userid, [
|
||||
'status' => '1',
|
||||
]);
|
||||
|
||||
return view('dashboard.announcements.read', [
|
||||
'title' => 'Detail Pengumuman',
|
||||
'announcement' => $announcement,
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy($id){
|
||||
try {
|
||||
$announcement = Announcement::with(['users'])->findOrFail(decrypt_id($id));
|
||||
@ -133,4 +131,25 @@ public function destroy($id){
|
||||
return response()->json(['message' => 'Gagal menghapus pengumuman.'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function read($id){
|
||||
$announcement = Announcement::with(['users'])->findOrFail(decrypt_id($id));
|
||||
|
||||
if(!in_array(Auth::id(), $announcement->users->pluck('id')->toArray())){
|
||||
abort(404, "Pengumuman tidak ditemukan.");
|
||||
}
|
||||
|
||||
try{
|
||||
$announcement->users()->updateExistingPivot(Auth::id(), [
|
||||
'status' => '1',
|
||||
]);
|
||||
}catch(\Exception $e){
|
||||
return redirect()->back()->with('failed-status', 'Gagal membaca pengumuman.');
|
||||
}
|
||||
|
||||
return view('dashboard.announcements.read', [
|
||||
'title' => 'Baca Pengumuman',
|
||||
'announcement' => $announcement,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,7 +28,6 @@ public function create(){
|
||||
|
||||
public function store(ClassificationRequest $request){
|
||||
$validatedData = $request->validated();
|
||||
$validatedData['enhancer_id'] = Auth::id();
|
||||
|
||||
try{
|
||||
$createdClassification = Classification::create($validatedData);
|
||||
@ -52,16 +51,15 @@ public function edit($id){
|
||||
|
||||
public function update(ClassificationRequest $request, $id){
|
||||
$validatedData = $request->validated();
|
||||
$validatedData['enhancer_id'] = Auth::id();
|
||||
|
||||
try{
|
||||
$classification = Classification::findOrFail(decrypt_id($id));
|
||||
$classification->update($validatedData);
|
||||
|
||||
return redirect()->route('dashboard.classifications.show', ['id' => encrypt_id($classification->id)])->with('success-status', 'Berhasil mengubah klasifikasi.');
|
||||
}catch(\Exception $e){
|
||||
return redirect()->back()->with('failed-status', 'Gagal mengubah klasifikasi.');
|
||||
}
|
||||
|
||||
return redirect()->route('dashboard.classifications.show', ['id' => encrypt_id($classification->id)])->with('success-status', 'Berhasil mengubah klasifikasi.');
|
||||
}
|
||||
|
||||
public function show($id){
|
||||
|
||||
@ -53,6 +53,8 @@ public function editRequest(){
|
||||
}
|
||||
|
||||
public function editRequestAction(Request $request){
|
||||
|
||||
try{
|
||||
if(!in_array(Auth::user()->company->edit_status, ['0', '2', '3'])){
|
||||
abort(404);
|
||||
}
|
||||
@ -63,25 +65,21 @@ public function editRequestAction(Request $request){
|
||||
'edit_description.required' => 'Deskripsi wajib diisi.',
|
||||
]);
|
||||
|
||||
if(!Auth::check()){
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$user = User::with(['company'])->findOrFail(Auth::id());
|
||||
$updatedCompany = $user->company->update([
|
||||
'edit_status' => '1',
|
||||
'edit_description' => $validatedData['edit_description']
|
||||
]);
|
||||
|
||||
if($updatedCompany){
|
||||
return redirect()->route('dashboard.companies.index')->with('success-status', 'Berhasil melakukan permohonan edit data perusahaan.');
|
||||
}else{
|
||||
}catch(\Exception $e){
|
||||
return redirect()->route('dashboard.companies.index')->with('failed-status', 'Gagal melakukan permohonan edit data perusahaan.');
|
||||
}
|
||||
|
||||
return redirect()->route('dashboard.companies.index')->with('success-status', 'Berhasil melakukan permohonan edit data perusahaan.');
|
||||
}
|
||||
|
||||
public function edit(){
|
||||
if(!in_array(Auth::user()->company->edit_status, ['2'])){
|
||||
if(Auth::user()->company->edit_status !== '2'){
|
||||
abort(404);
|
||||
}
|
||||
|
||||
@ -94,12 +92,14 @@ public function edit(){
|
||||
}
|
||||
|
||||
public function update(CompanyRequest $request){
|
||||
if(!in_array(Auth::user()->company->edit_status, ['2'])){
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$validatedData = $request->validated();
|
||||
|
||||
try{
|
||||
if(Auth::user()->company->edit_status !== '2'){
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$company = User::with(['company'])->findOrFail(Auth::id())->company;
|
||||
|
||||
$fileFieldMap = [
|
||||
@ -148,11 +148,11 @@ public function update(CompanyRequest $request){
|
||||
'edit_status' => '0',
|
||||
]);
|
||||
|
||||
if($updatedCompany){
|
||||
return redirect()->route('dashboard.companies.index')->with('success-status', 'Berhasil mengubah data perusahaan.');
|
||||
}else{
|
||||
}catch(\Exception $e){
|
||||
return redirect()->route('dashboard.companies.index')->with('failed-status', 'Gagal mengubah data perusahaan.');
|
||||
}
|
||||
|
||||
return redirect()->route('dashboard.companies.index')->with('success-status', 'Berhasil mengubah data perusahaan.');
|
||||
}
|
||||
|
||||
public function show($id, $type){
|
||||
@ -219,6 +219,8 @@ public function process(Request $request, $id, $type){
|
||||
}
|
||||
|
||||
public function processAcceptAction(Request $request, $id, $type, $category){
|
||||
|
||||
try{
|
||||
$user = User::with(['company'])->findOrFail(decrypt_id($id));
|
||||
|
||||
if(!in_array($category, ['account-status', 'edit-request'])){
|
||||
@ -238,13 +240,16 @@ public function processAcceptAction(Request $request, $id, $type, $category){
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}catch(\Exception $e){
|
||||
return response()->json([
|
||||
'message' => 'Berhasil menyetujui'.($category === 'edit-request' ? ' permohonan edit' : '').' perusahaan.'
|
||||
'failed-status' => 'Gagal menyetujui'.($category === 'edit-request' ? ' permohonan edit' : '').' perusahaan.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function processRejectAction(Request $request, $id, $type, $category){
|
||||
|
||||
try{
|
||||
$user = User::with(['company'])->findOrFail(decrypt_id($id));
|
||||
|
||||
if(!in_array($category, ['account-status', 'edit-request'])){
|
||||
@ -276,6 +281,9 @@ public function processRejectAction(Request $request, $id, $type, $category){
|
||||
]);
|
||||
}
|
||||
}
|
||||
}catch(\Exception $e){
|
||||
return redirect()->back()->with('faileds-status', 'Gagal melakukan proses.');
|
||||
}
|
||||
|
||||
return redirect()->route('dashboard.companies.index')->with('success-status', 'Berhasil menolak'.($category === 'edit-request' ? ' permohonan edit' : '').' perusahaan.');
|
||||
}
|
||||
|
||||
@ -20,15 +20,14 @@ public function index(){
|
||||
|
||||
public function create(){
|
||||
return view('dashboard.content-recaps.classifications.create', [
|
||||
'title' => "Tambah Klasifikasi Rekap Konten"
|
||||
'title' => "Buat Klasifikasi Rekap Konten Baru"
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(ContentRecapClassificationRequest $request){
|
||||
$validatedData = $request->validated();
|
||||
$validatedData['slug'] = Str::slug($validatedData['name']);
|
||||
$validatedData['enhancer_id'] = Auth::id();
|
||||
|
||||
try{
|
||||
$existedData = ContentRecapClassification::withTrashed()->where('slug', $validatedData['slug'])->first();
|
||||
|
||||
if($existedData && filled($existedData->deleted_at)){
|
||||
@ -38,12 +37,11 @@ public function store(ContentRecapClassificationRequest $request){
|
||||
}
|
||||
|
||||
$createdClassification = ContentRecapClassification::create($validatedData);
|
||||
|
||||
if($createdClassification){
|
||||
return redirect()->route('dashboard.content.recap.classifications.index')->with('success-status', 'Berhasil menambahkan klasifikasi rekap konten.');
|
||||
}else{
|
||||
}catch(\Exception $e){
|
||||
return redirect()->back()->with('failed-status', 'Gagal menambahkan klasifikasi rekap konten.');
|
||||
}
|
||||
|
||||
return redirect()->route('dashboard.content.recap.classifications.index')->with('success-status', 'Berhasil menambahkan klasifikasi rekap konten.');
|
||||
}
|
||||
|
||||
public function edit($id){
|
||||
@ -57,17 +55,15 @@ public function edit($id){
|
||||
|
||||
public function update(ContentRecapClassificationRequest $request, $id){
|
||||
$validatedData = $request->validated();
|
||||
$validatedData['slug'] = Str::slug($validatedData['name']);
|
||||
$validatedData['enhancer_id'] = Auth::id();
|
||||
|
||||
try{
|
||||
$contentRecapClassification = ContentRecapClassification::findOrFail(decrypt_id($id));
|
||||
$updatedContentRecapClassification = $contentRecapClassification->update($validatedData);
|
||||
|
||||
if($updatedContentRecapClassification){
|
||||
return redirect()->back()->with('success-status', 'Berhasil mengubah klasifikasi rekap konten.');
|
||||
}else{
|
||||
}catch(\Exception $e){
|
||||
return redirect()->back()->with('failed-status', 'Gagal mengubah klasifikasi rekap konten.');
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success-status', 'Berhasil mengubah klasifikasi rekap konten.');
|
||||
}
|
||||
|
||||
public function show($id){
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
@ -33,27 +35,23 @@ public function create(){
|
||||
|
||||
public function store(NewsRequest $request){
|
||||
$validatedData = $request->validated();
|
||||
$validatedData['slug'] = Str::slug($validatedData['title']);
|
||||
$validatedData['author_id'] = Auth::id();
|
||||
|
||||
$isNewsExists = News::where('slug', $validatedData['slug'])->first();
|
||||
$isNewsExists = News::withTrashed()->where('slug', $validatedData['slug'])->first();
|
||||
|
||||
if($isNewsExists){
|
||||
return redirect()->back()->with('failed-status', 'Maaf, berita dengan judul tersebut sudah pernah ditambahkan.');
|
||||
}
|
||||
|
||||
try{
|
||||
if($request->has('image')){
|
||||
$validatedData['image'] = store_file($validatedData['image'], '/uploads/news')['randomFileName'];
|
||||
}
|
||||
|
||||
|
||||
$createdNews = News::create($validatedData);
|
||||
|
||||
if($createdNews){
|
||||
return redirect()->route('dashboard.news.index')->with('success-status', 'Berhasil menambahkan berita.');
|
||||
}else{
|
||||
return redirect()->back()->with('failed-status', 'Gagal menambahkan berita.');
|
||||
}catch(\Exception $e){
|
||||
return redirect()->back()->with('failed-status', 'Gagal membuat berita baru.');
|
||||
}
|
||||
|
||||
return redirect()->route('dashboard.news.index')->with('success-status', 'Berhasil membuat berita baru.');
|
||||
}
|
||||
|
||||
public function edit($id){
|
||||
@ -68,6 +66,7 @@ public function edit($id){
|
||||
public function update(NewsRequest $request, $id){
|
||||
$validatedData = $request->validated();
|
||||
|
||||
try{
|
||||
$news = News::findOrFail(decrypt_id($id));
|
||||
|
||||
if($request->has('image')){
|
||||
@ -77,23 +76,20 @@ public function update(NewsRequest $request, $id){
|
||||
$validatedData['image'] = $news->image;
|
||||
}
|
||||
|
||||
$validatedData['slug'] = Str::slug($validatedData['title']);
|
||||
$validatedData['author_id'] = Auth::id();
|
||||
|
||||
$isNewsExists = News::where('slug', $validatedData['slug'])->first();
|
||||
|
||||
if($isNewsExists && $isNewsExists->id !== $news->id){
|
||||
return redirect()->back()->with('failed-status', 'Maaf, berita dengan judul tersebut sudah pernah ditambahkan.');
|
||||
}
|
||||
|
||||
$news = News::findOrFail(decrypt_id($id));
|
||||
$updatedNews = $news->update($validatedData);
|
||||
$news->update($validatedData);
|
||||
|
||||
if($updatedNews){
|
||||
return redirect()->back()->with('success-status', 'Berhasil mengubah berita.');
|
||||
}else{
|
||||
}catch(\Exception $e){
|
||||
return redirect()->back()->with('failed-status', 'Gagal mengubah berita.');
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success-status', 'Berhasil mengubah berita.');
|
||||
|
||||
}
|
||||
|
||||
public function show($id){
|
||||
@ -105,21 +101,31 @@ public function show($id){
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy($id){
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
DB::transaction(function () use ($id) {
|
||||
$news = News::findOrFail(decrypt_id($id));
|
||||
$news->update([
|
||||
'slug' => $news->slug.'-deleted-'. now()->timestamp
|
||||
]);
|
||||
$news->delete();
|
||||
|
||||
$newSlug = Str::limit($news->slug . '-deleted-' . now()->timestamp, 191);
|
||||
|
||||
$news->update([
|
||||
'slug' => $newSlug,
|
||||
]);
|
||||
|
||||
$news->delete();
|
||||
});
|
||||
|
||||
return response()->json(['message' => 'Berhasil menghapus berita.']);
|
||||
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
|
||||
return response()->json(['message' => 'Berita tidak ditemukan.'], 404);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Gagal menghapus berita: ' . $e->getMessage());
|
||||
return response()->json(['message' => 'Gagal menghapus berita.'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
$category = $request->input('category', 'all');
|
||||
|
||||
@ -44,7 +44,6 @@ public function create(Request $request){
|
||||
|
||||
public function store(SubClassificationRequest $request){
|
||||
$validatedData = $request->validated();
|
||||
$validatedData['enhancer_id'] = Auth::id();
|
||||
|
||||
try{
|
||||
$createdSubClassification = SubClassification::create($validatedData);
|
||||
@ -68,7 +67,6 @@ public function edit($id){
|
||||
|
||||
public function update(SubClassificationRequest $request, $id){
|
||||
$validatedData = $request->validated();
|
||||
$validatedData['enhancer_id'] = Auth::id();
|
||||
|
||||
try{
|
||||
$subClassification = SubClassification::findOrFail(decrypt_id($id));
|
||||
|
||||
@ -29,6 +29,7 @@ public function rules(): array
|
||||
'content' => ['required'],
|
||||
'link' => ['nullable', 'url'],
|
||||
'attachment' => ['nullable', 'file', 'mimes:pdf', 'max:2048'],
|
||||
'enhancer_id' => ['required'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -41,6 +42,17 @@ public function messages(): array
|
||||
'user_ids.*.required' => 'Media yang dipilih tidak boleh kosong.',
|
||||
'user_ids.*.exists' => 'Salah satu media yang dipilih tidak ditemukan.',
|
||||
'content.required' => 'Konten pengumuman harus diisi.',
|
||||
'link.url' => 'Format tautan/link tidak valid. Pastikan menggunakan format lengkap, misal: https://example.com.',
|
||||
'attachment.file' => 'Lampiran harus berupa file.',
|
||||
'attachment.mimes' => 'Lampiran hanya boleh berupa file PDF.',
|
||||
'attachment.max' => 'Ukuran lampiran maksimal 2MB.',
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'enhancer_id' => Auth::check() ? Auth::id() : null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,19 +26,11 @@ public function rules(): array
|
||||
return [
|
||||
'name' => ['required', 'max:100'],
|
||||
'status' => ['required', 'in:0,1'],
|
||||
'description' => ['nullable']
|
||||
'description' => ['nullable'],
|
||||
'enhancer_id' => ['required'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'description' => filled($this->description) ? $this->description : null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
@ -49,4 +41,12 @@ public function messages(): array
|
||||
'description.nullable' => 'Deskripsi boleh kosong jika tidak diperlukan.',
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'description' => filled($this->description) ? $this->description : null,
|
||||
'enhancer_id' => Auth::check() ? Auth::id() : null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ContentRecapClassificationRequest extends FormRequest
|
||||
{
|
||||
@ -25,6 +26,8 @@ public function rules(): array
|
||||
return [
|
||||
'name' => ['required', 'max:100'],
|
||||
'description' => ['nullable'],
|
||||
'slug' => ['required'],
|
||||
'enhancer_id' => ['required'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -36,4 +39,12 @@ public function messages(): array
|
||||
'description.nullable' => 'Deskripsi bersifat opsional.',
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'slug' => filled($this->name) ? Str::slug($this->name) : null,
|
||||
'enhancer_id' => Auth::check() ? Auth::id() : null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class NewsRequest extends FormRequest
|
||||
{
|
||||
@ -28,7 +29,9 @@ public function rules(): array
|
||||
'link' => ['nullable', 'url'],
|
||||
'tag' => ['nullable'],
|
||||
'category' => ['required', 'in:0,1'],
|
||||
'image' => ['nullable', 'image', 'mimes:png,jpg,jpeg', 'max:2048']
|
||||
'image' => ['nullable', 'image', 'mimes:png,jpg,jpeg', 'max:2048'],
|
||||
'slug' => ['required'],
|
||||
'enhancer_id' => ['required'],
|
||||
];
|
||||
|
||||
return $rules;
|
||||
@ -50,4 +53,12 @@ public function messages(): array
|
||||
'image.max' => 'Ukuran gambar tidak boleh lebih dari 4MB.',
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'slug' => filled($this->title) ? Str::slug($this->title) : null,
|
||||
'enhancer_id' => Auth::check() ? Auth::id() : null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,18 +26,11 @@ public function rules(): array
|
||||
'name' => ['required', 'max:100'],
|
||||
'classification_id' => ['required', 'exists:classifications,id'],
|
||||
'status' => ['required', 'in:0,1'],
|
||||
'description' => ['nullable']
|
||||
'description' => ['nullable'],
|
||||
'enhancer_id' => ['required'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'description' => filled($this->description) ? $this->description : null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
@ -51,4 +44,12 @@ public function messages(): array
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'description' => filled($this->description) ? $this->description : null,
|
||||
'enhancer_id' => Auth::check() ? Auth::id() : null,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user