<?php

namespace App\Http\Controllers\Dashboard;

use App\Http\Controllers\Controller;
use \App\Models\{Course};
use Illuminate\Http\Request;


class CourseController extends Controller
{
    public $courses;


    
    public function getCourses (Request $request) {
        try {
           $this->courses = Course::query()->when($request->search, fn ($q) => $q->where('course_name', "like", "%{$request->search}%"))->get();
            if ($this->courses) {
                return response()->json(['data' => $this->courses], 200);
            }
        } catch (\Throwable $th) {
            return response()->json(['error' => $th->getMessage(), 500]);
        }
    }
}
