tissue/app/Http/Controllers/SearchController.php

52 lines
1.4 KiB
PHP
Raw Normal View History

2018-09-06 23:48:54 +09:00
<?php
namespace App\Http\Controllers;
use App\Ejaculation;
use App\Tag;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
2018-09-06 23:48:54 +09:00
class SearchController extends Controller
{
public function index(Request $request)
{
$inputs = $request->validate([
'q' => 'required'
]);
$results = Ejaculation::query()
->whereHas('tags', function ($query) use ($inputs) {
$query->where('name', 'like', "%{$inputs['q']}%");
})
->whereHas('user', function ($query) {
$query->where('is_protected', false);
if (Auth::check()) {
$query->orWhere('id', Auth::id());
}
})
2018-09-06 23:48:54 +09:00
->where('is_private', false)
->orderBy('ejaculated_date', 'desc')
->with(['user', 'tags'])
2019-04-05 23:10:26 +09:00
->withLikes()
->paginate(20)
->appends($inputs);
2018-09-06 23:48:54 +09:00
return view('search.index')->with(compact('inputs', 'results'));
}
public function relatedTag(Request $request)
{
$inputs = $request->validate([
'q' => 'required'
]);
$results = Tag::query()
->where('name', 'like', "%{$inputs['q']}%")
->paginate(50)
->appends($inputs);
2018-09-06 23:48:54 +09:00
return view('search.relatedTag')->with(compact('inputs', 'results'));
}
2019-01-15 00:05:01 +09:00
}