refactor: part one
This commit is contained in:
parent
c622a9b069
commit
5c972770a6
@ -11,43 +11,39 @@
|
|||||||
|
|
||||||
class AiringProofThemeController extends Controller
|
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(){
|
public function index(){
|
||||||
return view('dashboard.airing-proof-themes.index', [
|
return view('dashboard.airing-proof-themes.index', [
|
||||||
'title' => "Tema Bukti Tayang"
|
'title' => "Data Tema Bukti Tayang"
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(){
|
public function create(){
|
||||||
return view('dashboard.airing-proof-themes.create', [
|
return view('dashboard.airing-proof-themes.create', [
|
||||||
'title' => "Tambah Tema Bukti Tayang"
|
'title' => "Buat Tema Bukti Tayang Baru"
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(AiringProofThemeRequest $request){
|
public function store(AiringProofThemeRequest $request){
|
||||||
$validatedData = $request->validated();
|
$validatedData = $request->validated();
|
||||||
|
|
||||||
if($this->checkExistedData($validatedData['slug'], true)){
|
|
||||||
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.');
|
|
||||||
}
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
AiringProofTheme::create($validatedData);
|
$existing = AiringProofTheme::withTrashed()
|
||||||
return redirect()->back()->with('success-status', 'Berhasil menambahkan tema bukti tayang.');
|
->where('slug', $validatedData['slug'])
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($existing?->trashed()) {
|
||||||
|
return redirect()->back()->with('data-exists', $validatedData['slug']);
|
||||||
|
} elseif ($existing) {
|
||||||
|
return redirect()->back()
|
||||||
|
->with('failed-status', 'Tema dengan nama dan tahun tersebut sudah ada.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$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){
|
}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{
|
try{
|
||||||
$airingProofTheme = AiringProofTheme::findOrFail(decrypt_id($id));
|
$airingProofTheme = AiringProofTheme::findOrFail(decrypt_id($id));
|
||||||
$airingProofTheme->update($validatedData);
|
$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){
|
}catch(\Exception $e){
|
||||||
return redirect()->back()->with('failed-status', 'Gagal mengubah tema bukti tayang.');
|
return redirect()->back()->with('failed-status', 'Gagal mengubah tema bukti tayang.');
|
||||||
}
|
}
|
||||||
@ -94,20 +91,25 @@ public function destroy($id){
|
|||||||
|
|
||||||
public function restore($slug)
|
public function restore($slug)
|
||||||
{
|
{
|
||||||
$airingProofTheme = AiringProofTheme::withTrashed()
|
|
||||||
|
try{
|
||||||
|
$airingProofTheme = AiringProofTheme::withTrashed()
|
||||||
->where('slug', $slug)
|
->where('slug', $slug)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (!$airingProofTheme) {
|
if (!$airingProofTheme) {
|
||||||
return redirect()->back()->with('failed-status', 'Tema tidak ditemukan.');
|
return redirect()->back()->with('failed-status', 'Tema tidak ditemukan.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filled($airingProofTheme->deleted_at)) {
|
if (filled($airingProofTheme->deleted_at)) {
|
||||||
$airingProofTheme->restore();
|
$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.');
|
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 App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class AnnouncementController extends Controller
|
class AnnouncementController extends Controller
|
||||||
{
|
{
|
||||||
public function index(Request $request){
|
public function index(Request $request){
|
||||||
|
|
||||||
$category = $request->input('category', 'general');
|
$category = $request->input('category', 'general');
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'title' => 'Pengumuman',
|
'title' => 'Pengumuman',
|
||||||
'category' => $category
|
'category' => $category
|
||||||
];
|
];
|
||||||
|
|
||||||
if(is_role(['1'])){
|
if(is_role(['1'])){
|
||||||
return view('dashboard.announcements.index', $data);
|
return view('dashboard.announcements.index', $data);
|
||||||
}else if(is_role(['3'])){
|
}else if(is_role(['3'])){
|
||||||
@ -28,34 +31,44 @@ public function index(Request $request){
|
|||||||
|
|
||||||
public function create(){
|
public function create(){
|
||||||
return view('dashboard.announcements.create', [
|
return view('dashboard.announcements.create', [
|
||||||
'title' => 'Tambah Pengumuman',
|
'title' => 'Buat Pengumuman Baru',
|
||||||
'users' => User::all()
|
'users' => User::all()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(AnnouncementRequest $request){
|
public function store(AnnouncementRequest $request){
|
||||||
$validatedData = $request->validated();
|
$validatedData = $request->validated();
|
||||||
$validatedData['enhancer_id'] = Auth::id();
|
|
||||||
|
|
||||||
if($request->hasFile('attachment')){
|
try{
|
||||||
$validatedData['attachment'] = store_file($validatedData['attachment'], '/uploads/announcements')['randomFileName'];
|
|
||||||
|
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() < 1){
|
||||||
|
throw new \Exception("Data tidak valid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $announcement;
|
||||||
|
});
|
||||||
|
|
||||||
|
}catch(\Exception $e){
|
||||||
|
return redirect()->back()->with('failed-status', 'Gagal membuat pengumuman baru');
|
||||||
}
|
}
|
||||||
|
|
||||||
$announcement = Announcement::create($validatedData);
|
return redirect()->route('dashboard.announcements.index')->with('success-status', 'Berhasil membuat pengumuman baru.')->with('new_data', encrypt_id($announcement->id));
|
||||||
$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');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit($id){
|
public function edit($id){
|
||||||
$announcement = Announcement::with(['users'])->findOrFail(decrypt_id($id));
|
$announcement = Announcement::with(['users'])->findOrFail(decrypt_id($id));
|
||||||
|
|
||||||
return view('dashboard.announcements.edit', [
|
return view('dashboard.announcements.edit', [
|
||||||
'title' => 'Tambah Pengumuman',
|
'title' => 'Ubah Pengumuman',
|
||||||
'announcement' => $announcement,
|
'announcement' => $announcement,
|
||||||
'users' => User::all(),
|
'users' => User::all(),
|
||||||
'selectedUsersIds' => $announcement->users->pluck('id')->toArray()
|
'selectedUsersIds' => $announcement->users->pluck('id')->toArray()
|
||||||
@ -64,31 +77,34 @@ public function edit($id){
|
|||||||
|
|
||||||
public function update(AnnouncementRequest $request, $id){
|
public function update(AnnouncementRequest $request, $id){
|
||||||
$validatedData = $request->validated();
|
$validatedData = $request->validated();
|
||||||
$validatedData['enhancer_id'] = Auth::id();
|
|
||||||
|
|
||||||
$announcement = Announcement::with(['users'])->findOrFail(decrypt_id($id));
|
try{
|
||||||
|
|
||||||
if($request->hasFile('attachment')){
|
$announcement = Announcement::with(['users'])->findOrFail(decrypt_id($id));
|
||||||
$validatedData['attachment'] = store_file($validatedData['attachment'], '/uploads/announcements')['randomFileName'];
|
|
||||||
delete_file('uploads/announcements/'.$announcement->attachment);
|
|
||||||
}else{
|
|
||||||
$validatedData['attachment'] = $announcement->attachment;
|
|
||||||
}
|
|
||||||
|
|
||||||
$announcement->update($validatedData);
|
DB::transaction(function () use($request, $validatedData, $announcement){
|
||||||
if ($request->has('user_ids')) {
|
if($request->hasFile('attachment')){
|
||||||
$mediaData = [];
|
$validatedData['attachment'] = store_file($validatedData['attachment'], '/uploads/announcements')['randomFileName'];
|
||||||
foreach ($validatedData['user_ids'] as $userId) {
|
delete_file('uploads/announcements/'.$announcement->attachment);
|
||||||
$mediaData[$userId] = ['status' => '0'];
|
}else{
|
||||||
}
|
$validatedData['attachment'] = $announcement->attachment;
|
||||||
|
}
|
||||||
|
|
||||||
$announcement->users()->sync($mediaData);
|
$announcement->update($validatedData);
|
||||||
}
|
if ($request->has('user_ids')) {
|
||||||
|
$mediaData = [];
|
||||||
|
foreach ($validatedData['user_ids'] as $userId) {
|
||||||
|
$mediaData[$userId] = ['status' => '0'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$announcement->users()->sync($mediaData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if ($announcement->users()->count() > 0) {
|
|
||||||
return redirect()->back()->with('success-status', 'Berhasil mengubah pengumuman.');
|
return redirect()->back()->with('success-status', 'Berhasil mengubah pengumuman.');
|
||||||
} else {
|
}catch(\Exception $e){
|
||||||
return redirect()->back()->with('failed-status', 'Gagal mengubah pengumuman');
|
|
||||||
|
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){
|
public function destroy($id){
|
||||||
try {
|
try {
|
||||||
$announcement = Announcement::with(['users'])->findOrFail(decrypt_id($id));
|
$announcement = Announcement::with(['users'])->findOrFail(decrypt_id($id));
|
||||||
@ -133,4 +131,25 @@ public function destroy($id){
|
|||||||
return response()->json(['message' => 'Gagal menghapus pengumuman.'], 500);
|
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){
|
public function store(ClassificationRequest $request){
|
||||||
$validatedData = $request->validated();
|
$validatedData = $request->validated();
|
||||||
$validatedData['enhancer_id'] = Auth::id();
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$createdClassification = Classification::create($validatedData);
|
$createdClassification = Classification::create($validatedData);
|
||||||
@ -52,16 +51,15 @@ public function edit($id){
|
|||||||
|
|
||||||
public function update(ClassificationRequest $request, $id){
|
public function update(ClassificationRequest $request, $id){
|
||||||
$validatedData = $request->validated();
|
$validatedData = $request->validated();
|
||||||
$validatedData['enhancer_id'] = Auth::id();
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$classification = Classification::findOrFail(decrypt_id($id));
|
$classification = Classification::findOrFail(decrypt_id($id));
|
||||||
$classification->update($validatedData);
|
$classification->update($validatedData);
|
||||||
|
|
||||||
return redirect()->route('dashboard.classifications.show', ['id' => encrypt_id($classification->id)])->with('success-status', 'Berhasil mengubah klasifikasi.');
|
|
||||||
}catch(\Exception $e){
|
}catch(\Exception $e){
|
||||||
return redirect()->back()->with('failed-status', 'Gagal mengubah klasifikasi.');
|
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){
|
public function show($id){
|
||||||
|
|||||||
@ -53,35 +53,33 @@ public function editRequest(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function editRequestAction(Request $request){
|
public function editRequestAction(Request $request){
|
||||||
if(!in_array(Auth::user()->company->edit_status, ['0', '2', '3'])){
|
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
|
|
||||||
$validatedData = $request->validate([
|
try{
|
||||||
'edit_description' => ['required'],
|
if(!in_array(Auth::user()->company->edit_status, ['0', '2', '3'])){
|
||||||
], [
|
abort(404);
|
||||||
'edit_description.required' => 'Deskripsi wajib diisi.',
|
}
|
||||||
]);
|
|
||||||
|
|
||||||
if(!Auth::check()){
|
$validatedData = $request->validate([
|
||||||
abort(404);
|
'edit_description' => ['required'],
|
||||||
}
|
], [
|
||||||
|
'edit_description.required' => 'Deskripsi wajib diisi.',
|
||||||
|
]);
|
||||||
|
|
||||||
$user = User::with(['company'])->findOrFail(Auth::id());
|
$user = User::with(['company'])->findOrFail(Auth::id());
|
||||||
$updatedCompany = $user->company->update([
|
$updatedCompany = $user->company->update([
|
||||||
'edit_status' => '1',
|
'edit_status' => '1',
|
||||||
'edit_description' => $validatedData['edit_description']
|
'edit_description' => $validatedData['edit_description']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if($updatedCompany){
|
}catch(\Exception $e){
|
||||||
return redirect()->route('dashboard.companies.index')->with('success-status', 'Berhasil melakukan permohonan edit data perusahaan.');
|
|
||||||
}else{
|
|
||||||
return redirect()->route('dashboard.companies.index')->with('failed-status', 'Gagal melakukan permohonan edit data perusahaan.');
|
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(){
|
public function edit(){
|
||||||
if(!in_array(Auth::user()->company->edit_status, ['2'])){
|
if(Auth::user()->company->edit_status !== '2'){
|
||||||
abort(404);
|
abort(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,65 +92,67 @@ public function edit(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function update(CompanyRequest $request){
|
public function update(CompanyRequest $request){
|
||||||
if(!in_array(Auth::user()->company->edit_status, ['2'])){
|
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
|
|
||||||
$validatedData = $request->validated();
|
$validatedData = $request->validated();
|
||||||
|
|
||||||
$company = User::with(['company'])->findOrFail(Auth::id())->company;
|
try{
|
||||||
|
if(Auth::user()->company->edit_status !== '2'){
|
||||||
$fileFieldMap = [
|
abort(404);
|
||||||
'company_director_nik_doc' => 'director_nik_doc',
|
|
||||||
'company_deed_incorporation_doc' => 'deed_incorporation_doc',
|
|
||||||
'company_trade_license_doc' => 'trade_license_doc',
|
|
||||||
'company_tax_id_number_doc' => 'tax_id_number_doc',
|
|
||||||
'company_taxable_enterprise_doc' => 'taxable_enterprise_doc',
|
|
||||||
'company_annual_tax_return_doc' => 'annual_tax_return_doc',
|
|
||||||
'company_domicile_certificate_doc' => 'domicile_certificate_doc',
|
|
||||||
'company_profile_doc' => 'profile_doc',
|
|
||||||
];
|
|
||||||
|
|
||||||
$companyFileNames = [];
|
|
||||||
|
|
||||||
foreach ($fileFieldMap as $requestKey => $dbField) {
|
|
||||||
if ($request->hasFile($requestKey) && filled($validatedData[$requestKey])) {
|
|
||||||
$companyFileNames[$requestKey] = store_file($validatedData[$requestKey], '/uploads/companies')['randomFileName'];
|
|
||||||
} else {
|
|
||||||
$companyFileNames[$requestKey] = $company->{$dbField};
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$updatedCompany = $company->update([
|
$company = User::with(['company'])->findOrFail(Auth::id())->company;
|
||||||
'name' => $validatedData['company_name'],
|
|
||||||
'email' => $validatedData['company_email'],
|
|
||||||
'address' => $validatedData['company_address'],
|
|
||||||
'director_name' => $validatedData['company_director_name'],
|
|
||||||
'director_nik' => $validatedData['company_director_nik'],
|
|
||||||
'director_nik_doc' => $companyFileNames['company_director_nik_doc'],
|
|
||||||
'deed_incorporation' => $validatedData['company_deed_incorporation'],
|
|
||||||
'deed_incorporation_doc' => $companyFileNames['company_deed_incorporation_doc'],
|
|
||||||
'trade_license' => $validatedData['company_trade_license'],
|
|
||||||
'trade_license_doc' => $companyFileNames['company_trade_license_doc'],
|
|
||||||
'tax_id_number' => $validatedData['company_tax_id_number'],
|
|
||||||
'tax_id_number_doc' => $companyFileNames['company_tax_id_number_doc'],
|
|
||||||
'taxable_enterprise' => $validatedData['company_taxable_enterprise'],
|
|
||||||
'taxable_enterprise_doc' => $companyFileNames['company_taxable_enterprise_doc'],
|
|
||||||
'annual_tax_return' => $validatedData['company_annual_tax_return'],
|
|
||||||
'annual_tax_return_doc' => $companyFileNames['company_annual_tax_return_doc'],
|
|
||||||
'domicile_certificate' => $validatedData['company_domicile_certificate'],
|
|
||||||
'domicile_certificate_doc' => $companyFileNames['company_domicile_certificate_doc'],
|
|
||||||
'profile' => $validatedData['company_profile'],
|
|
||||||
'profile_doc' => $companyFileNames['company_profile_doc'],
|
|
||||||
'edit_description' => null,
|
|
||||||
'edit_status' => '0',
|
|
||||||
]);
|
|
||||||
|
|
||||||
if($updatedCompany){
|
$fileFieldMap = [
|
||||||
return redirect()->route('dashboard.companies.index')->with('success-status', 'Berhasil mengubah data perusahaan.');
|
'company_director_nik_doc' => 'director_nik_doc',
|
||||||
}else{
|
'company_deed_incorporation_doc' => 'deed_incorporation_doc',
|
||||||
|
'company_trade_license_doc' => 'trade_license_doc',
|
||||||
|
'company_tax_id_number_doc' => 'tax_id_number_doc',
|
||||||
|
'company_taxable_enterprise_doc' => 'taxable_enterprise_doc',
|
||||||
|
'company_annual_tax_return_doc' => 'annual_tax_return_doc',
|
||||||
|
'company_domicile_certificate_doc' => 'domicile_certificate_doc',
|
||||||
|
'company_profile_doc' => 'profile_doc',
|
||||||
|
];
|
||||||
|
|
||||||
|
$companyFileNames = [];
|
||||||
|
|
||||||
|
foreach ($fileFieldMap as $requestKey => $dbField) {
|
||||||
|
if ($request->hasFile($requestKey) && filled($validatedData[$requestKey])) {
|
||||||
|
$companyFileNames[$requestKey] = store_file($validatedData[$requestKey], '/uploads/companies')['randomFileName'];
|
||||||
|
} else {
|
||||||
|
$companyFileNames[$requestKey] = $company->{$dbField};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$updatedCompany = $company->update([
|
||||||
|
'name' => $validatedData['company_name'],
|
||||||
|
'email' => $validatedData['company_email'],
|
||||||
|
'address' => $validatedData['company_address'],
|
||||||
|
'director_name' => $validatedData['company_director_name'],
|
||||||
|
'director_nik' => $validatedData['company_director_nik'],
|
||||||
|
'director_nik_doc' => $companyFileNames['company_director_nik_doc'],
|
||||||
|
'deed_incorporation' => $validatedData['company_deed_incorporation'],
|
||||||
|
'deed_incorporation_doc' => $companyFileNames['company_deed_incorporation_doc'],
|
||||||
|
'trade_license' => $validatedData['company_trade_license'],
|
||||||
|
'trade_license_doc' => $companyFileNames['company_trade_license_doc'],
|
||||||
|
'tax_id_number' => $validatedData['company_tax_id_number'],
|
||||||
|
'tax_id_number_doc' => $companyFileNames['company_tax_id_number_doc'],
|
||||||
|
'taxable_enterprise' => $validatedData['company_taxable_enterprise'],
|
||||||
|
'taxable_enterprise_doc' => $companyFileNames['company_taxable_enterprise_doc'],
|
||||||
|
'annual_tax_return' => $validatedData['company_annual_tax_return'],
|
||||||
|
'annual_tax_return_doc' => $companyFileNames['company_annual_tax_return_doc'],
|
||||||
|
'domicile_certificate' => $validatedData['company_domicile_certificate'],
|
||||||
|
'domicile_certificate_doc' => $companyFileNames['company_domicile_certificate_doc'],
|
||||||
|
'profile' => $validatedData['company_profile'],
|
||||||
|
'profile_doc' => $companyFileNames['company_profile_doc'],
|
||||||
|
'edit_description' => null,
|
||||||
|
'edit_status' => '0',
|
||||||
|
]);
|
||||||
|
|
||||||
|
}catch(\Exception $e){
|
||||||
return redirect()->route('dashboard.companies.index')->with('failed-status', 'Gagal mengubah data perusahaan.');
|
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){
|
public function show($id, $type){
|
||||||
@ -219,62 +219,70 @@ public function process(Request $request, $id, $type){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function processAcceptAction(Request $request, $id, $type, $category){
|
public function processAcceptAction(Request $request, $id, $type, $category){
|
||||||
$user = User::with(['company'])->findOrFail(decrypt_id($id));
|
|
||||||
|
|
||||||
if(!in_array($category, ['account-status', 'edit-request'])){
|
try{
|
||||||
abort(404);
|
$user = User::with(['company'])->findOrFail(decrypt_id($id));
|
||||||
}
|
|
||||||
|
|
||||||
if(is_role(['1']) && in_array($category, ['account-status', 'edit-request'])){
|
if(!in_array($category, ['account-status', 'edit-request'])){
|
||||||
if($category === 'account-status' && $user->status === '0'){
|
abort(404);
|
||||||
$user->update([
|
|
||||||
'status' => '1'
|
|
||||||
]);
|
|
||||||
|
|
||||||
Mail::to($user->email)->send(new AccountVerification($user, 'accepted'));
|
|
||||||
}else if($category === 'edit-request' && $user->company->edit_status === '1'){
|
|
||||||
$user->company->update([
|
|
||||||
'edit_status' => '2'
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json([
|
if(is_role(['1']) && in_array($category, ['account-status', 'edit-request'])){
|
||||||
'message' => 'Berhasil menyetujui'.($category === 'edit-request' ? ' permohonan edit' : '').' perusahaan.'
|
if($category === 'account-status' && $user->status === '0'){
|
||||||
]);
|
$user->update([
|
||||||
|
'status' => '1'
|
||||||
|
]);
|
||||||
|
|
||||||
|
Mail::to($user->email)->send(new AccountVerification($user, 'accepted'));
|
||||||
|
}else if($category === 'edit-request' && $user->company->edit_status === '1'){
|
||||||
|
$user->company->update([
|
||||||
|
'edit_status' => '2'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch(\Exception $e){
|
||||||
|
return response()->json([
|
||||||
|
'failed-status' => 'Gagal menyetujui'.($category === 'edit-request' ? ' permohonan edit' : '').' perusahaan.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processRejectAction(Request $request, $id, $type, $category){
|
public function processRejectAction(Request $request, $id, $type, $category){
|
||||||
$user = User::with(['company'])->findOrFail(decrypt_id($id));
|
|
||||||
|
|
||||||
if(!in_array($category, ['account-status', 'edit-request'])){
|
try{
|
||||||
abort(404);
|
$user = User::with(['company'])->findOrFail(decrypt_id($id));
|
||||||
}
|
|
||||||
|
|
||||||
if(is_role(['1']) && in_array($category, ['account-status', 'edit-request'])){
|
if(!in_array($category, ['account-status', 'edit-request'])){
|
||||||
|
abort(404);
|
||||||
$validatedData = $request->validate([
|
|
||||||
'rejection_reason' => ['required'],
|
|
||||||
], [
|
|
||||||
'rejection_reason.required' => 'Alasan penolakan wajib diisi.',
|
|
||||||
]);
|
|
||||||
|
|
||||||
if($category === 'account-status' && $user->status === '0'){
|
|
||||||
$user->update([
|
|
||||||
'status' => '2'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$user->company->update([
|
|
||||||
'rejection_reason' => $validatedData['rejection_reason']
|
|
||||||
]);
|
|
||||||
|
|
||||||
Mail::to($user->email)->send(new AccountVerification($user, 'rejected', $validatedData['rejection_reason']));
|
|
||||||
}else if($category === 'edit-request' && $user->company->edit_status === '1'){
|
|
||||||
$user->company->update([
|
|
||||||
'edit_status' => '3',
|
|
||||||
'edit_rejection_reason' => $validatedData['rejection_reason']
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(is_role(['1']) && in_array($category, ['account-status', 'edit-request'])){
|
||||||
|
|
||||||
|
$validatedData = $request->validate([
|
||||||
|
'rejection_reason' => ['required'],
|
||||||
|
], [
|
||||||
|
'rejection_reason.required' => 'Alasan penolakan wajib diisi.',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if($category === 'account-status' && $user->status === '0'){
|
||||||
|
$user->update([
|
||||||
|
'status' => '2'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user->company->update([
|
||||||
|
'rejection_reason' => $validatedData['rejection_reason']
|
||||||
|
]);
|
||||||
|
|
||||||
|
Mail::to($user->email)->send(new AccountVerification($user, 'rejected', $validatedData['rejection_reason']));
|
||||||
|
}else if($category === 'edit-request' && $user->company->edit_status === '1'){
|
||||||
|
$user->company->update([
|
||||||
|
'edit_status' => '3',
|
||||||
|
'edit_rejection_reason' => $validatedData['rejection_reason']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}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.');
|
return redirect()->route('dashboard.companies.index')->with('success-status', 'Berhasil menolak'.($category === 'edit-request' ? ' permohonan edit' : '').' perusahaan.');
|
||||||
|
|||||||
@ -20,30 +20,28 @@ public function index(){
|
|||||||
|
|
||||||
public function create(){
|
public function create(){
|
||||||
return view('dashboard.content-recaps.classifications.create', [
|
return view('dashboard.content-recaps.classifications.create', [
|
||||||
'title' => "Tambah Klasifikasi Rekap Konten"
|
'title' => "Buat Klasifikasi Rekap Konten Baru"
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(ContentRecapClassificationRequest $request){
|
public function store(ContentRecapClassificationRequest $request){
|
||||||
$validatedData = $request->validated();
|
$validatedData = $request->validated();
|
||||||
$validatedData['slug'] = Str::slug($validatedData['name']);
|
|
||||||
$validatedData['enhancer_id'] = Auth::id();
|
|
||||||
|
|
||||||
$existedData = ContentRecapClassification::withTrashed()->where('slug', $validatedData['slug'])->first();
|
try{
|
||||||
|
$existedData = ContentRecapClassification::withTrashed()->where('slug', $validatedData['slug'])->first();
|
||||||
|
|
||||||
if($existedData && filled($existedData->deleted_at)){
|
if($existedData && filled($existedData->deleted_at)){
|
||||||
return redirect()->back()->with('data-exists', $validatedData['slug']);
|
return redirect()->back()->with('data-exists', $validatedData['slug']);
|
||||||
}elseif($existedData){
|
}elseif($existedData){
|
||||||
return redirect()->back()->with('failed-status', 'Tema dengan nama tersebut sudah ada.');
|
return redirect()->back()->with('failed-status', 'Tema dengan nama tersebut sudah ada.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$createdClassification = ContentRecapClassification::create($validatedData);
|
$createdClassification = ContentRecapClassification::create($validatedData);
|
||||||
|
}catch(\Exception $e){
|
||||||
if($createdClassification){
|
|
||||||
return redirect()->route('dashboard.content.recap.classifications.index')->with('success-status', 'Berhasil menambahkan klasifikasi rekap konten.');
|
|
||||||
}else{
|
|
||||||
return redirect()->back()->with('failed-status', 'Gagal menambahkan klasifikasi rekap konten.');
|
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){
|
public function edit($id){
|
||||||
@ -57,17 +55,15 @@ public function edit($id){
|
|||||||
|
|
||||||
public function update(ContentRecapClassificationRequest $request, $id){
|
public function update(ContentRecapClassificationRequest $request, $id){
|
||||||
$validatedData = $request->validated();
|
$validatedData = $request->validated();
|
||||||
$validatedData['slug'] = Str::slug($validatedData['name']);
|
|
||||||
$validatedData['enhancer_id'] = Auth::id();
|
|
||||||
|
|
||||||
$contentRecapClassification = ContentRecapClassification::findOrFail(decrypt_id($id));
|
try{
|
||||||
$updatedContentRecapClassification = $contentRecapClassification->update($validatedData);
|
$contentRecapClassification = ContentRecapClassification::findOrFail(decrypt_id($id));
|
||||||
|
$updatedContentRecapClassification = $contentRecapClassification->update($validatedData);
|
||||||
if($updatedContentRecapClassification){
|
}catch(\Exception $e){
|
||||||
return redirect()->back()->with('success-status', 'Berhasil mengubah klasifikasi rekap konten.');
|
|
||||||
}else{
|
|
||||||
return redirect()->back()->with('failed-status', 'Gagal mengubah klasifikasi rekap konten.');
|
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){
|
public function show($id){
|
||||||
|
|||||||
@ -9,6 +9,8 @@
|
|||||||
use Barryvdh\DomPDF\Facade\Pdf;
|
use Barryvdh\DomPDF\Facade\Pdf;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
|
||||||
@ -33,27 +35,23 @@ public function create(){
|
|||||||
|
|
||||||
public function store(NewsRequest $request){
|
public function store(NewsRequest $request){
|
||||||
$validatedData = $request->validated();
|
$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){
|
if($isNewsExists){
|
||||||
return redirect()->back()->with('failed-status', 'Maaf, berita dengan judul tersebut sudah pernah ditambahkan.');
|
return redirect()->back()->with('failed-status', 'Maaf, berita dengan judul tersebut sudah pernah ditambahkan.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($request->has('image')){
|
try{
|
||||||
$validatedData['image'] = store_file($validatedData['image'], '/uploads/news')['randomFileName'];
|
if($request->has('image')){
|
||||||
|
$validatedData['image'] = store_file($validatedData['image'], '/uploads/news')['randomFileName'];
|
||||||
|
}
|
||||||
|
$createdNews = News::create($validatedData);
|
||||||
|
}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.');
|
||||||
$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.');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit($id){
|
public function edit($id){
|
||||||
@ -68,32 +66,30 @@ public function edit($id){
|
|||||||
public function update(NewsRequest $request, $id){
|
public function update(NewsRequest $request, $id){
|
||||||
$validatedData = $request->validated();
|
$validatedData = $request->validated();
|
||||||
|
|
||||||
$news = News::findOrFail(decrypt_id($id));
|
try{
|
||||||
|
$news = News::findOrFail(decrypt_id($id));
|
||||||
|
|
||||||
if($request->has('image')){
|
if($request->has('image')){
|
||||||
delete_file('uploads/news/'.$news->image);
|
delete_file('uploads/news/'.$news->image);
|
||||||
$validatedData['image'] = store_file($validatedData['image'], '/uploads/news')['randomFileName'];
|
$validatedData['image'] = store_file($validatedData['image'], '/uploads/news')['randomFileName'];
|
||||||
}else{
|
}else{
|
||||||
$validatedData['image'] = $news->image;
|
$validatedData['image'] = $news->image;
|
||||||
}
|
}
|
||||||
|
|
||||||
$validatedData['slug'] = Str::slug($validatedData['title']);
|
$isNewsExists = News::where('slug', $validatedData['slug'])->first();
|
||||||
$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.');
|
||||||
|
}
|
||||||
|
|
||||||
if($isNewsExists && $isNewsExists->id !== $news->id){
|
$news->update($validatedData);
|
||||||
return redirect()->back()->with('failed-status', 'Maaf, berita dengan judul tersebut sudah pernah ditambahkan.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$news = News::findOrFail(decrypt_id($id));
|
}catch(\Exception $e){
|
||||||
$updatedNews = $news->update($validatedData);
|
|
||||||
|
|
||||||
if($updatedNews){
|
|
||||||
return redirect()->back()->with('success-status', 'Berhasil mengubah berita.');
|
|
||||||
}else{
|
|
||||||
return redirect()->back()->with('failed-status', 'Gagal mengubah berita.');
|
return redirect()->back()->with('failed-status', 'Gagal mengubah berita.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return redirect()->back()->with('success-status', 'Berhasil mengubah berita.');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show($id){
|
public function show($id){
|
||||||
@ -105,21 +101,31 @@ public function show($id){
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy($id){
|
public function destroy($id)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
$news = News::findOrFail(decrypt_id($id));
|
DB::transaction(function () use ($id) {
|
||||||
$news->update([
|
$news = News::findOrFail(decrypt_id($id));
|
||||||
'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.']);
|
return response()->json(['message' => 'Berhasil menghapus berita.']);
|
||||||
|
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
|
||||||
|
return response()->json(['message' => 'Berita tidak ditemukan.'], 404);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
Log::error('Gagal menghapus berita: ' . $e->getMessage());
|
||||||
return response()->json(['message' => 'Gagal menghapus berita.'], 500);
|
return response()->json(['message' => 'Gagal menghapus berita.'], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function export(Request $request)
|
public function export(Request $request)
|
||||||
{
|
{
|
||||||
$category = $request->input('category', 'all');
|
$category = $request->input('category', 'all');
|
||||||
|
|||||||
@ -44,7 +44,6 @@ public function create(Request $request){
|
|||||||
|
|
||||||
public function store(SubClassificationRequest $request){
|
public function store(SubClassificationRequest $request){
|
||||||
$validatedData = $request->validated();
|
$validatedData = $request->validated();
|
||||||
$validatedData['enhancer_id'] = Auth::id();
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$createdSubClassification = SubClassification::create($validatedData);
|
$createdSubClassification = SubClassification::create($validatedData);
|
||||||
@ -68,7 +67,6 @@ public function edit($id){
|
|||||||
|
|
||||||
public function update(SubClassificationRequest $request, $id){
|
public function update(SubClassificationRequest $request, $id){
|
||||||
$validatedData = $request->validated();
|
$validatedData = $request->validated();
|
||||||
$validatedData['enhancer_id'] = Auth::id();
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$subClassification = SubClassification::findOrFail(decrypt_id($id));
|
$subClassification = SubClassification::findOrFail(decrypt_id($id));
|
||||||
|
|||||||
@ -29,6 +29,7 @@ public function rules(): array
|
|||||||
'content' => ['required'],
|
'content' => ['required'],
|
||||||
'link' => ['nullable', 'url'],
|
'link' => ['nullable', 'url'],
|
||||||
'attachment' => ['nullable', 'file', 'mimes:pdf', 'max:2048'],
|
'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.*.required' => 'Media yang dipilih tidak boleh kosong.',
|
||||||
'user_ids.*.exists' => 'Salah satu media yang dipilih tidak ditemukan.',
|
'user_ids.*.exists' => 'Salah satu media yang dipilih tidak ditemukan.',
|
||||||
'content.required' => 'Konten pengumuman harus diisi.',
|
'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 [
|
return [
|
||||||
'name' => ['required', 'max:100'],
|
'name' => ['required', 'max:100'],
|
||||||
'status' => ['required', 'in:0,1'],
|
'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
|
public function messages(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -49,4 +41,12 @@ public function messages(): array
|
|||||||
'description.nullable' => 'Deskripsi boleh kosong jika tidak diperlukan.',
|
'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\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class ContentRecapClassificationRequest extends FormRequest
|
class ContentRecapClassificationRequest extends FormRequest
|
||||||
{
|
{
|
||||||
@ -25,6 +26,8 @@ public function rules(): array
|
|||||||
return [
|
return [
|
||||||
'name' => ['required', 'max:100'],
|
'name' => ['required', 'max:100'],
|
||||||
'description' => ['nullable'],
|
'description' => ['nullable'],
|
||||||
|
'slug' => ['required'],
|
||||||
|
'enhancer_id' => ['required'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,4 +39,12 @@ public function messages(): array
|
|||||||
'description.nullable' => 'Deskripsi bersifat opsional.',
|
'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\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class NewsRequest extends FormRequest
|
class NewsRequest extends FormRequest
|
||||||
{
|
{
|
||||||
@ -28,7 +29,9 @@ public function rules(): array
|
|||||||
'link' => ['nullable', 'url'],
|
'link' => ['nullable', 'url'],
|
||||||
'tag' => ['nullable'],
|
'tag' => ['nullable'],
|
||||||
'category' => ['required', 'in:0,1'],
|
'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;
|
return $rules;
|
||||||
@ -50,4 +53,12 @@ public function messages(): array
|
|||||||
'image.max' => 'Ukuran gambar tidak boleh lebih dari 4MB.',
|
'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'],
|
'name' => ['required', 'max:100'],
|
||||||
'classification_id' => ['required', 'exists:classifications,id'],
|
'classification_id' => ['required', 'exists:classifications,id'],
|
||||||
'status' => ['required', 'in:0,1'],
|
'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
|
public function messages(): array
|
||||||
{
|
{
|
||||||
return [
|
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