mardi 28 février 2017

Laravel 5 Search Not Working as expected

I`m new to the Laravel 5.4.i wanted to developed search when i enter id number need to fetch service from the database called new.but according to this code it is not functioning.it just show all the services without the exact value related to its id.All i want is if i enter id 1 ..i need to fetch out service related to id=1 and display it in search.blade.phpplease help me!

Here Is my Search.blade.php

 <!DOCTYPE html>
<html lang="">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Laravel</title>

        <!-- Fonts -->
        <link href="http://ift.tt/2dHeAcp" rel="stylesheet" type="text/css">

        <!-- Styles -->

    </head>
    <body>
       <form action="search" method="post">
       <label>Search by Id!</label><br>
       <input type="text" name="Search" /><br>
       <input type="hidden" value="" name="_token" />
       <input type="submit" name="submit" value="Search">
       </form>



        <table class="table table-bordered table-hover" >

            <thead>
                <th>Name</th>
            </thead>
            <tbody>
                @foreach($customers as $customer)

                    <td></td>

                @endforeach
            </tbody>   
        </table>

    </body>
</html>

Here is my Controller UserController

public function search_code(Request $request){

    $query = $request->search;
    $customers = DB::table('news')->where('id', 'LIKE',"%$query%")->get();
     return view('search' , compact('search', 'customers'));

    }

Here Is My Route

Route::post('search', 'UserController@search_code');



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2laonyt
via IFTTT

Aucun commentaire:

Enregistrer un commentaire