Tìm kiếm nhiều trường trong một bảng, search many tables (ok)
C:\xampp\htdocs\api\app\Http\Controllers\Api\V1\HomeController.php
<?php
namespace App\Http\Controllers\Api\V1;
use Illuminate\Http\Request;
use App\Models\CategoryPost;
use App\Models\Post;
class HomeController extends Controller {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$categories = CategoryPost::all();
$posts = Post::with('category')->get();
$posts_randon = Post::all()->random(6);
$posts_views = Post::orderBy('views','DESC')->take('6')->get();
return view("pages.main")->with(compact('categories','posts','posts_randon','posts_views'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create() {
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request) {
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id) {
echo '<pre>';
var_export($id);
echo '</pre>';
die("gggg");
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function tim_kiem() {
$keyword = $_GET['keyword'];
$category_posts = Post::with("category")->where('title','LIKE','%'.$keyword.'%')->orWhere('short_desc','LIKE','%'.$keyword.'%')->get();
$categories = CategoryPost::all();
$posts = Post::with('category')->get();
$posts_randon = Post::all()->random(6);
$posts_views = Post::orderBy('views','DESC')->take('6')->get();
return view("pages.search")->with(compact('categories','category_posts','posts','posts_randon','posts_views'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id) {
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id) {
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
//
}
}C:\xampp\htdocs\api\resources\views\pages\search.blade.php
C:\xampp\htdocs\api\resources\views\layout.blade.php
C:\xampp\htdocs\api\routes\web.php
Last updated
Was this helpful?