<?php
namespace App\Http\Controllers;
use App\Models\tag_event;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Crypt;
class TagEventController extends Controller
{
public function index(){
$data['tag_event']=tag_event::get();
return view('tag_event.index')->with($data);
}
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'color' => 'required',
]);
$data = [
'name' => $request->name,
'color'=> $request->color,
'editable'=>1
];
tag_event::create($data);
return redirect()->route('tag_event.index')->with('success', 'Data successfully added');
}
public function update(request $request,string $id){
try {
$decryptedId = Crypt::decryptString($id);
$request->validate([
'name' => 'required',
'color' => 'required',
]);
$data = [
'name' => $request->name,
'color'=> $request->color,
'editable'=>1
];
tag_event::where('id', $decryptedId)->update($data);
return redirect()->route('tag_event.index')->with('success', 'Data successfully changed');
} catch (DecryptException $e) {
return redirect()->back()->with('error', 'Invalid ID');
}
}
public function destroy(string $id)
{
try {
$decryptedId = Crypt::decryptString($id);
tag_event::where('id', $decryptedId)->delete();
return redirect()->route('tag_event.index')->with('delete', 'Data successfully deleted');
} catch (DecryptException $e) {
return redirect()->back()->with('error', 'Invalid ID');
}
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]