Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function searchEvents(Request $request)
- {
- $partip_arr = explode(" ", $request->keywords);
- $events = Event::where(function($q) use ($partip_arr) {
- $q->where('name', 'like', '%' . $partip_arr . '%');
- foreach ($partip_arr as $index => $value) {
- if ($index === 0) {
- continue;
- }
- $q->orWhere('name', 'like', '%' . $value . '%');
- }
- })
- ->orWhere(function($q) use ($partip_arr) {
- $q->where('description', 'like', '%' . $partip_arr . '%');
- foreach ($partip_arr as $index => $value) {
- if ($index === 0) {
- continue;
- }
- $q->orWhere('name', 'like', '%' . $value . '%');
- }
- })
- ->orWhere(function($q) use ($partip_arr) {
- $q->where('participants', 'like', '%' . $partip_arr . '%');
- foreach ($partip_arr as $index => $value) {
- if ($index === 0) {
- continue;
- }
- $q->orWhere('name', 'like', '%' . $value . '%');
- }
- });
- $count = $events->count();
- $events = $events->offset(request('offset'))
- ->take(20)
- ->latest()->get();
- return response()->json(['events' => $events, 'count' => $count]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement