Skip to content

Commit

Permalink
Add Prevent Duplicate Column
Browse files Browse the repository at this point in the history
  • Loading branch information
ShoyebWritesCode committed Aug 20, 2024
1 parent 8e427ef commit de82144
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions app/Http/Controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,17 @@ public function addColumn()
'type' => ['required', 'in:string,number,date'],
]);

Auth::user()->account->contactCustomColumns()->create($column);
if (Auth::user()->account->contactCustomColumns()->where('name', $column['name'])->exists()) {
return Redirect::back()->with('error', 'Column already exists.');
} else {

return Redirect::back()->with('success', 'Column added.');
Auth::user()->account->contactCustomColumns()->create($column);

//send status 200 code
return response()->json([], 200);

return Redirect::back()->with('success', 'Column added.')->json([], 200);
}
}

public function updateCustomColumns(Contact $contact): RedirectResponse
Expand Down
6 changes: 3 additions & 3 deletions resources/js/Pages/Contacts/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<div class="flex items-center justify-between mt-4">
<label for="type" class="block text-sm font-medium text-gray-700">Data Type</label>
<select id="type"
class="mt-1 block w-1/2 py-2text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md">
class="mt-1 block w-1/2 py-1 border-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md">
<option>string</option>
<option>number</option>
<option>date</option>
Expand Down Expand Up @@ -110,7 +110,7 @@
<th v-for="csvColumn in csvColumns" :key="csvColumn" class="border-b font-bold text-left p-2">
<span v-if="selectedDbColumns[csvColumn] || matchingColumn(csvColumn)">{{
matchingColumn(csvColumn) ? matchingColumn(csvColumn).name : selectedDbColumns[csvColumn]
}}</span>
}}</span>
</th>
</tr>
</thead>
Expand All @@ -119,7 +119,7 @@
<td v-for="csvColumn in csvColumns" :key="csvColumn" class="border-b p-2">
<span v-if="selectedDbColumns[csvColumn] || matchingColumn(csvColumn)">{{
getValueForColumn(row, csvColumn) !== 'N/A' ? getValueForColumn(row, csvColumn) : ''
}}</span>
}}</span>
</td>
</tr>
</tbody>
Expand Down

0 comments on commit de82144

Please sign in to comment.