如何通过Ajax在Laravel中创建搜索网络

时间:2019-09-08 05:23:31

标签: ajax laravel

<?php

namespace App\Http\Controllers;

use DB;
use Illuminate\Http\Request;

class SearchController extends Controller
{
    public function search(Request $request) {
        $text = $request->input('text');

        $patients = DB::table('patients')
                        ->where('firstname', 'Like', $text)
                        ->get();

        // return the results
        return response()->json($patients);
    }
}

2 个答案:

答案 0 :(得分:0)

以这种方式输入您的退货!

import component_exported_as_default, {component_1,component2} from 'components/my_component.js'
function App(){
   return(
      <div className="APP">
         <component_exported_as_default>
         <component_1>
         <component2>
      </div>
   )
}

答案 1 :(得分:0)

   $filter = $request->tagname;
   $events = Event::where([
             ['status', '=', 1],
             ['search_tags','LIKE',"%{$filter}%"]
          ])->get();

   return response($events);