Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\A..

Decoded Output download

<?php 
 
namespace App\Http\Controllers; 
 
use Illuminate\Http\Request; 
use App\Models\Accounts; 
use Illuminate\Support\Str; 
use DB; 
use Carbon\Carbon; 
use Illuminate\Support\Facades\Hash; 
use DataTables; 
 
class AccountsController extends Controller 
{ 
    // Method to fetch accounts data and render the accounts view 
    public function index(Request $request) 
    { 
        if ($request->ajax()) { 
            // Fetch accounts data ordered by the latest 
            $data = Accounts::latest()->get(); 
 
            // Render DataTables for the fetched data 
            return Datatables::of($data) 
                ->addColumn('action', function ($row) { 
                    // Generate action buttons for each account row 
                    $btn = '<div class="btn-group">'; 
                    $btn .= '<a href="'. route('Account', $row->id) .'" title="Remove Account" id="'.$row->id.'" class="btn btn-info btn-sm"><i class="fas fa-edit"></i></a>'; 
                    $btn .= '<button type="button" id="'.$row->id.'" class="deleteBtn btn btn-danger btn-sm"><i class="fas fa-remove"></i></button>'; 
                    $btn .= '</div>'; 
 
                    return $btn; 
                }) 
 
                ->editColumn('status', function ($row) { 
                    // Edit status column to display "Active" or "Inactive" 
                    return $row->status == 1 ? 'Active' : 'Inactive'; 
                }) 
                ->editColumn('created_at', function($row) { 
                    // Edit created_at column to display the timestamp 
                    return $row->created_at;  
                }) 
                ->editColumn('updated_at', function($row) { 
                    // Edit updated_at column to display the timestamp 
                    return $row->updated_at;  
                }) 
                ->rawColumns(['action']) 
                ->make(true); 
        } 
 
        return view('accounts'); // Render the accounts view 
    } 
 
    // Method to delete a account 
    public function delete(Request $request) 
    { 
        $id = $request->id; 
        $info = Accounts::where('uniqueID', $id)->first(); 
 
        if (!$info) { 
            return response()->json(['error' => 'Account not found.'], 404); 
        } 
 
        $count = DB::table('invoices')->where('created_by', $info->id)->count(); 
        if($count == 0) { 
            $info->delete(); 
            return response()->json(['success' => 'Account deleted successfully.']); 
        } else { 
            return response()->json(['error' => 'Account has invoices.']);    
        } 
    } 
 
    // Method to render the account view for adding or updating a account 
    public function view($id = null) 
    { 
        $info = null; 
        $route = 'saveaccount'; 
 
         $accounttypes = DB::table('accounttypes')->orderby('name')->get(); 
 
        if ($id) { 
            $route = 'updateaccount'; 
            $info = Accounts::where('id', $id)->first(); 
        } 
 
        $data = [ 
            'accounttypes' => $accounttypes, 
            'route' => $route, 
            'info' => $info, 
        ]; 
 
        return view('account', ['data' => $data]); // Render the account view 
    } 
 
public function save(Request $request) 
{ 
    $validatedData = $request->validate([ 
        'name' => 'required|unique:accounts,name', 
        'accountType' => 'required', 
        'cityName' => 'required', 
        'status' => 'required|in:0,1', 
    ]); 
 
    $accountType = $request->input('accountType'); 
 
    // Check if the accountType already exists in the accounttypes table 
    $existingAccountType = DB::table('accounttypes')->where('name', $accountType)->first(); 
 
    if (!$existingAccountType) { 
        // Insert the new accountType into the accounttypes table 
        DB::table('accounttypes')->insert([ 
            'name' => $accountType 
        ]); 
    } 
 
    // Find the maximum uniqueID for the same accountType 
    $maxId = Accounts::where('accountType', $accountType)->max('uniqueID'); 
 
    // Extract the numeric part from the max ID and increment it 
    $newIdNumber = 1; // Default to 1 if no existing ID is found 
    if ($maxId) { 
        $newIdNumber = $maxId + 1; 
    } 
 
    $uniqueID = $newIdNumber; 
 
    // Create a new account instance 
    $info = new Accounts(); 
    $info->name = $request->input('name'); 
    $info->uniqueID = $uniqueID; 
    $info->accountType = $accountType; 
    $info->shopName = $request->input('shopName'); 
    $info->cityName = $request->input('cityName'); 
    $info->districtName = $request->input('districtName'); 
    $info->tehsilName = $request->input('tehsilName'); 
    $info->mobileNumber = $request->input('mobileNumber'); 
    $info->email = $request->input('email'); 
    $info->status = $request->input('status'); 
    $info->created_at = Carbon::now(); 
 
    // Save the new account information 
    $info->save(); 
 
    return response()->json(['success' => 'Account information saved successfully.']); 
} 
 
 
 
   // Method to update an existing account 
// Method to update an existing account 
public function update(Request $request) 
{ 
    $validatedData = $request->validate([ 
        'name' => 'required', 
        'id' => 'required|unique:accounts,id,' . $request->input('id') . ',id', 
        'accountType' => 'required', 
        'status' => 'required|in:0,1', 
    ]); 
 
    $accountType = $request->input('accountType'); 
 
    // Check if the accountType already exists in the accounttypes table 
    $existingAccountType = DB::table('accounttypes')->where('name', $accountType)->first(); 
 
    if (!$existingAccountType) { 
        // Insert the new accountType into the accounttypes table 
        DB::table('accounttypes')->insert([ 
            'name' => $accountType 
        ]); 
    } 
 
    // Fetch the account to be updated 
    $info = Accounts::where('id', $request->input('id'))->first(); 
 
    if ($info) { 
        // Update account information 
        $info->name = $request->input('name'); 
        $info->accountType = $accountType; 
        $info->shopName = $request->input('shopName'); 
        $info->cityName = $request->input('cityName'); 
        $info->districtName = $request->input('districtName'); 
        $info->tehsilName = $request->input('tehsilName'); 
        $info->mobileNumber = $request->input('mobileNumber'); 
        $info->email = $request->input('email'); 
        $info->description = $request->input('description'); 
        $info->status = $request->input('status'); 
        $info->updated_at = Carbon::now(); 
 
        // Save the updated account information 
        $info->save(); 
 
        return response()->json(['success' => 'Account info updated successfully']); 
    } 
 
    return response()->json(['error' => 'Account not found.'], 404); 
} 
 
 
 
} 
 ?>

Did this file decode correctly?

Original Code

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Accounts;
use Illuminate\Support\Str;
use DB;
use Carbon\Carbon;
use Illuminate\Support\Facades\Hash;
use DataTables;

class AccountsController extends Controller
{
    // Method to fetch accounts data and render the accounts view
    public function index(Request $request)
    {
        if ($request->ajax()) {
            // Fetch accounts data ordered by the latest
            $data = Accounts::latest()->get();

            // Render DataTables for the fetched data
            return Datatables::of($data)
                ->addColumn('action', function ($row) {
                    // Generate action buttons for each account row
                    $btn = '<div class="btn-group">';
                    $btn .= '<a href="'. route('Account', $row->id) .'" title="Remove Account" id="'.$row->id.'" class="btn btn-info btn-sm"><i class="fas fa-edit"></i></a>';
                    $btn .= '<button type="button" id="'.$row->id.'" class="deleteBtn btn btn-danger btn-sm"><i class="fas fa-remove"></i></button>';
                    $btn .= '</div>';

                    return $btn;
                })

                ->editColumn('status', function ($row) {
                    // Edit status column to display "Active" or "Inactive"
                    return $row->status == 1 ? 'Active' : 'Inactive';
                })
                ->editColumn('created_at', function($row) {
                    // Edit created_at column to display the timestamp
                    return $row->created_at; 
                })
                ->editColumn('updated_at', function($row) {
                    // Edit updated_at column to display the timestamp
                    return $row->updated_at; 
                })
                ->rawColumns(['action'])
                ->make(true);
        }

        return view('accounts'); // Render the accounts view
    }

    // Method to delete a account
    public function delete(Request $request)
    {
        $id = $request->id;
        $info = Accounts::where('uniqueID', $id)->first();

        if (!$info) {
            return response()->json(['error' => 'Account not found.'], 404);
        }

        $count = DB::table('invoices')->where('created_by', $info->id)->count();
        if($count == 0) {
            $info->delete();
            return response()->json(['success' => 'Account deleted successfully.']);
        } else {
            return response()->json(['error' => 'Account has invoices.']);   
        }
    }

    // Method to render the account view for adding or updating a account
    public function view($id = null)
    {
        $info = null;
        $route = 'saveaccount';

         $accounttypes = DB::table('accounttypes')->orderby('name')->get();

        if ($id) {
            $route = 'updateaccount';
            $info = Accounts::where('id', $id)->first();
        }

        $data = [
            'accounttypes' => $accounttypes,
            'route' => $route,
            'info' => $info,
        ];

        return view('account', ['data' => $data]); // Render the account view
    }

public function save(Request $request)
{
    $validatedData = $request->validate([
        'name' => 'required|unique:accounts,name',
        'accountType' => 'required',
        'cityName' => 'required',
        'status' => 'required|in:0,1',
    ]);

    $accountType = $request->input('accountType');

    // Check if the accountType already exists in the accounttypes table
    $existingAccountType = DB::table('accounttypes')->where('name', $accountType)->first();

    if (!$existingAccountType) {
        // Insert the new accountType into the accounttypes table
        DB::table('accounttypes')->insert([
            'name' => $accountType
        ]);
    }

    // Find the maximum uniqueID for the same accountType
    $maxId = Accounts::where('accountType', $accountType)->max('uniqueID');

    // Extract the numeric part from the max ID and increment it
    $newIdNumber = 1; // Default to 1 if no existing ID is found
    if ($maxId) {
        $newIdNumber = $maxId + 1;
    }

    $uniqueID = $newIdNumber;

    // Create a new account instance
    $info = new Accounts();
    $info->name = $request->input('name');
    $info->uniqueID = $uniqueID;
    $info->accountType = $accountType;
    $info->shopName = $request->input('shopName');
    $info->cityName = $request->input('cityName');
    $info->districtName = $request->input('districtName');
    $info->tehsilName = $request->input('tehsilName');
    $info->mobileNumber = $request->input('mobileNumber');
    $info->email = $request->input('email');
    $info->status = $request->input('status');
    $info->created_at = Carbon::now();

    // Save the new account information
    $info->save();

    return response()->json(['success' => 'Account information saved successfully.']);
}



   // Method to update an existing account
// Method to update an existing account
public function update(Request $request)
{
    $validatedData = $request->validate([
        'name' => 'required',
        'id' => 'required|unique:accounts,id,' . $request->input('id') . ',id',
        'accountType' => 'required',
        'status' => 'required|in:0,1',
    ]);

    $accountType = $request->input('accountType');

    // Check if the accountType already exists in the accounttypes table
    $existingAccountType = DB::table('accounttypes')->where('name', $accountType)->first();

    if (!$existingAccountType) {
        // Insert the new accountType into the accounttypes table
        DB::table('accounttypes')->insert([
            'name' => $accountType
        ]);
    }

    // Fetch the account to be updated
    $info = Accounts::where('id', $request->input('id'))->first();

    if ($info) {
        // Update account information
        $info->name = $request->input('name');
        $info->accountType = $accountType;
        $info->shopName = $request->input('shopName');
        $info->cityName = $request->input('cityName');
        $info->districtName = $request->input('districtName');
        $info->tehsilName = $request->input('tehsilName');
        $info->mobileNumber = $request->input('mobileNumber');
        $info->email = $request->input('email');
        $info->description = $request->input('description');
        $info->status = $request->input('status');
        $info->updated_at = Carbon::now();

        // Save the updated account information
        $info->save();

        return response()->json(['success' => 'Account info updated successfully']);
    }

    return response()->json(['error' => 'Account not found.'], 404);
}



}

Function Calls

None

Variables

None

Stats

MD5 cbb1a74ffe2c671144c89ee45347e22b
Eval Count 0
Decode Time 86 ms