Table structure model:
Table: user
id
name
email
Table: employee
id
user_id
cpf
We have these two tables in the database, how to make a script, which takes the id of the user table and checks in the employee table, if the user_id are the same, if it is the same it deletes the record from the two tables, if it is not the same it deletes the record only from the user table
Rota
Route::delete('/plano/{id}',[ChangePlanController::class, 'destroy'])->name('plan.destroy');
views
<form action="{{ route('plan.destroy', $profissional->user_id)}}" method="POST">
@method('DELETE')
@csrf
<button type="submit" class="text-indigo-600 hover:text-indigo-900" >Excluir</button>
</form>
Controller
public function destroy($id)
{
if(!$user = UserEmployee::find($id))
return redirect()->route('plan.searchUsers');
$user->delete();
return redirect()->route('plan.searchUsers');
}
2
Answers
Please Make Sure yor model have Relationship if not please try to make Relationship b/n Tables