# How to delete record through page events from detail page from master page

**URL:** <https://forum.radsystems.io/t/how-to-delete-record-through-page-events-from-detail-page-from-master-page/633>\
**Category:** PHPRad Vue\
**Created:** [December 1, 2021, 7:50am UTC](https://forum.radsystems.io/t/how-to-delete-record-through-page-events-from-detail-page-from-master-page/633 "2021-12-01T07:50:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrmst](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phrmst](https://forum.radsystems.io/u/phrmst)\
**Post date:** [December 1, 2021, 7:50am UTC](https://forum.radsystems.io/t/how-to-delete-record-through-page-events-from-detail-page-from-master-page/633/1 "2021-12-01T07:50:18Z")

</div>

Hi,  
I want to delete detail page record which has same protocol \_ref as master table. I want to accomplish this through clicking on delete icon in master list.

 ![Untitled](https://forum.radsystems.io/uploads/default/original/1X/53fa99668cd68421ca76f0017a62e7f3c07e4b24.png)

I have written the below code of master\_page events: before delete.

```auto
 private function beforeDelete($rec_id, $record){
DB::table('stability_protocol_detail')->where('protocol_ref', '=', $record->protocol_ref)->delete(); }

```

But it shows the below error:

 ![Untitled1](https://forum.radsystems.io/uploads/default/original/1X/3396a93a8673ea5e3fdac5d624228a73d9fafa30.png)

Please help me to figure it.

Thanks

---

<div class="post-metadata">

**Author:** ![willvin](https://forum.radsystems.io/user_avatar/forum.radsystems.io/willvin/32/7_2.png) [@willvin](https://forum.radsystems.io/u/willvin)\
**Post date:** [December 1, 2021, 10:46am UTC](https://forum.radsystems.io/t/how-to-delete-record-through-page-events-from-detail-page-from-master-page/633/2 "2021-12-01T10:46:21Z")

</div>

@phrmst this is a bug, which has been reported to the dev. The error there is that the second parameter of the **beforeDelete** and other similar **Page Event** functions are not being parsed by the app when it calls the function. You can remove the error by setting the **$record** to **null**.

```php
private function beforeDelete($rec_id, $record=null){

```

OR

You could locate where the function is being called and parse the second parameter to the function. It would look something similar to this, but might not be exactly, in terms of the variable name.  
from this

```php
beforeDelete($rec_id);

```

to this

```php
beforeDelete($rec_id, $record);

```

---

<div class="post-metadata">

**Author:** ![phrmst](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phrmst](https://forum.radsystems.io/u/phrmst)\
**Post date:** [December 2, 2021, 3:51am UTC](https://forum.radsystems.io/t/how-to-delete-record-through-page-events-from-detail-page-from-master-page/633/3 "2021-12-02T03:51:59Z")

</div>

I have solved my problem. The main problem was in controller.

I have changed the code in respective controller through addition of $record variable.

```auto
function delete(Request $request, $rec_id = null){
        $arr_id = explode(",", $rec_id);
        $query = Stability_Protocol_Header::query();
        $this->beforeDelete($rec_id, $record);
        $query->whereIn("id", $arr_id);
        $query->delete();
        return $this->respond($arr_id);
    }

```

to

```auto
function delete(Request $request, $rec_id = null){
        $arr_id = explode(",", $rec_id);
        $query = Stability_Protocol_Header::query();
        $record = $query->findOrFail($rec_id, Stability_Protocol_Header::editFields());
        $this->beforeDelete($rec_id, $record);
        $query->whereIn("id", $arr_id);
        $query->delete();
        return $this->respond($arr_id);
    }

```

Thanks
