File: /var/www/html/orbidirectory.com/app/Http/Controllers/SubscribeController.php
<?php
namespace App\Http\Controllers;
use App\Models\Subscriber;
use Illuminate\Http\Request;
use App\Models\Subscription;
use Yajra\DataTables\Facades\DataTables;
class SubscribeController extends Controller
{
public function index()
{
return view('admin.subscribe.index');
}
public function list()
{
try {
$subscription =Subscriber::orderBy('created_at', 'ASC');
$datatable = DataTables::eloquent($subscription)
->addColumn("action", function ($row) {
return view('admin.subscribe.action', compact('row'));
})
->rawColumns(['action'])
->make(true);
return $datatable;
} catch (\Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function destroy($id)
{
try {
$subscription = Subscriber::findOrFail($id); // Find the subscription by ID
$subscription->delete(); // Delete the record
return redirect()->route('subscribe.index')->with('success', 'Subscriber record deleted successfully.');
} catch (\Exception $e) {
return redirect()->route('subscribe.index')->with('error', 'Something went wrong: ' . $e->getMessage());
}
}
}