55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\BasicAuthAdmin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\AiTool;
|
|
use Illuminate\Http\Request;
|
|
|
|
class AIToolListController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$view = $request->input('view', 'all');
|
|
|
|
$ai_tool_list = AiTool::orderBy('created_at', 'DESC')
|
|
->when($view == 'emailed', function ($query) {
|
|
$query->where('has_emailed', true);
|
|
})
|
|
->when($view == 'not_emailed', function ($query) {
|
|
$query->where('has_emailed', false);
|
|
})
|
|
->when($view == 'all', function ($query) {
|
|
|
|
})
|
|
->orderBy('created_at', 'DESC')
|
|
->paginate(50);
|
|
|
|
$ai_tool_list_count =
|
|
|
|
$counts = (object) [
|
|
'all' => AiTool::count(),
|
|
'emailed' => AiTool::where('has_emailed', true)->count(),
|
|
'not_emailed' => AiTool::where('has_emailed', false)->count(),
|
|
];
|
|
|
|
return view('ba.aitoollist', compact('ai_tool_list', 'counts', 'view'));
|
|
}
|
|
|
|
public function setToEmailed(Request $request)
|
|
{
|
|
$ai_tool = AiTool::find($request->input('id'));
|
|
|
|
if (is_null($ai_tool)) {
|
|
return redirect()->back()->with('error', 'AI Tool not found.');
|
|
}
|
|
|
|
$ai_tool->has_emailed = true;
|
|
$ai_tool->email = $request->input('email');
|
|
|
|
if ($ai_tool->save()) {
|
|
return redirect()->back()->with('success', 'Saved successfully.');
|
|
}
|
|
}
|
|
}
|