lundi 28 janvier 2019

How to delete data in 3 relation table in laravel 5.7

I am trying to delete data on 3 relation table using laravel 5.7, when I am trying it on 2 relation table, it's run well, but when I'm trying it in 3 relation table, it does not work.

this is my table look like:

table 1 : group_access

|----|------------|
| id | group_name |
|----|------------|
| 67 |     test   |
|----|------------|

table 2 : fa_group_access

|----|-----------------|--------|
| id | group_access_id | name   |
|----|-----------------|--------|
|  1 |     67          | john   |
|----|-----------------|--------|

table 3 : survey_group_access

|----|-----------------|---------------|
| id | group_access_id | code_survey   |
|----|-----------------|---------------|
|  1 |     67          | SF-001        |
|----|-----------------|---------------|

and this is my function in the controller to delete the data:

public function destroy($id)
{
    $group = Groups::findOrFail($id);

    if($group->delete())
    {   
        Survey_group_access::where('group_access_id', $id)->get();
        FA_Group_Access::where('group_access_id', $id)->get();
        return response()->json(['status'=>'success']);    
    }   
}

and i got an error sql like this :

SQLSTATE[23000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]The DELETE statement conflicted with the REFERENCE constraint "survey_group_access_group_access_id_foreign". The conflict occurred in database "aetra2", table "dbo.survey_group_access", column 'group_access_id'. (SQL: delete from [group_access] where [id] = 67)

How to fix this error?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2RT8flt
via IFTTT

Aucun commentaire:

Enregistrer un commentaire