Welcome Guest, Not a member yet? Register   Sign In
Delete method failing
#1

I'm running into a strange issue with record (soft) deletes, and I can't track down where it's coming from. 

Checking my logs, I see that it does attempt to delete the record but the ID is '$'. I also checked the HTML source, and the ID is placed correctly in the delete path.  

Help...

Controller:
PHP Code:
    public function deleteUser($id null)
    {
        $model = new UserModel();
        $model->delete($id);
        $query $model->getLastQuery();
        log_message('notice'$query);

        return redirect()->back()->withInput();
    

Model:
PHP Code:
protected $useSoftDeletes true;

    
    
protected function initialize(): void
    
{
        parent::initialize();

        $this->allowedFields = [
            ...$this->allowedFields,

            'customerid',
            'name',
            'company',
            'address',
            'address2',
            'city',
            'state',
            'country',
            'postalcode',
            'phone_cc',
            'phone',
            'mobilenocc',
            'mobileno'
        ];

    }


    public function deleteUser($id)
    {
        return $this->delete($id);
    

View:
PHP Code:
<a href="<?= base_url('admin/users/delete/') . $user->id ?>">Delete</a


Route:
PHP Code:
$routes->get('users/delete/(:num)''Admin\Users::deleteUser/$'); 

Logs:
Code:
UPDATE `users` SET `deleted_at` = '2023-04-28 01:08:29', `updated_at` = '2023-04-28 01:08:29'
WHERE `id` IN ('$')
AND `deleted_at` IS NULL
Reply
#2

(This post was last modified: 04-27-2023, 07:49 PM by BilltheCat.)

Never mind, I found it. The route only had the '$' , so that's what was fed into the delete function:

$routes->get('users/delete/(:num)', 'Admin\Users::deleteUser/$1');
Reply
#3

PHP Code:
$routes->get('users/delete/(:num)''Admin\Users::deleteUser/$'); 

// should be
$routes->get('users/delete/(:num)''Admin\Users::deleteUser/$1'); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

Thanks? lol, yeah, that's what I said.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB