2022-03-05 16:02:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Providers;
|
|
|
|
use DataTables;
|
|
|
|
use Illuminate\Http\Request;
|
2022-03-05 16:58:25 +01:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
2022-03-05 16:02:12 +01:00
|
|
|
|
|
|
|
class ProvidersController extends Controller
|
|
|
|
{
|
|
|
|
public function index()
|
|
|
|
{
|
2022-05-09 07:39:03 +02:00
|
|
|
$providers = Providers::allProviders();
|
2022-03-05 16:02:12 +01:00
|
|
|
return view('providers.index', compact(['providers']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
return view('providers.create');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$request->validate([
|
2022-10-20 02:06:44 +02:00
|
|
|
'provider_name' => 'required|string|min:2'
|
2022-03-05 16:02:12 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
Providers::create([
|
|
|
|
'name' => $request->provider_name
|
|
|
|
]);
|
|
|
|
|
2022-05-09 07:39:03 +02:00
|
|
|
Cache::forget('providers');
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('providers.index')
|
|
|
|
->with('success', 'Provider Created Successfully.');
|
|
|
|
}
|
|
|
|
|
2022-03-05 16:58:25 +01:00
|
|
|
public function show(Providers $provider)
|
|
|
|
{
|
2022-05-15 13:01:02 +02:00
|
|
|
$data = Providers::showServicesForProvider($provider->id);
|
2022-03-05 16:58:25 +01:00
|
|
|
|
|
|
|
return view('providers.show', compact(['provider', 'data']));
|
|
|
|
}
|
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
public function destroy(Providers $provider)
|
|
|
|
{
|
|
|
|
$items = Providers::find($provider->id);
|
|
|
|
|
|
|
|
$items->delete();
|
|
|
|
|
2022-05-09 07:39:03 +02:00
|
|
|
Cache::forget('providers');
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('providers.index')
|
|
|
|
->with('success', 'Provider was deleted Successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProviders(Request $request)
|
|
|
|
{
|
|
|
|
if ($request->ajax()) {
|
|
|
|
$data = Providers::latest()->get();
|
|
|
|
$dt = Datatables::of($data)
|
|
|
|
->addIndexColumn()
|
2022-03-05 16:58:25 +01:00
|
|
|
->addColumn('action', function ($row) {
|
2022-03-05 16:02:12 +01:00
|
|
|
$actionBtn = '<a href="javascript:void(0)" class="edit btn btn-success btn-sm">Edit</a> <a href="javascript:void(0)" class="delete btn btn-danger btn-sm">Delete</a>';
|
|
|
|
return $actionBtn;
|
|
|
|
})
|
|
|
|
->rawColumns(['action'])
|
|
|
|
->make(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|