iklan

✔ Laravel 5 Tutorial : Simple Search Function Using Get Method In Laravel 5.3

Laravel 5.3 tutorial : How to create simple search function using "GET" method in laravel 5.3? The search box can be reuse in other index as well to make tidy codes.

At the previews lessons, we have learn how to make simple ajax crud in laravel 5.3, please read Laravel 5 CRUD using AJAX & Modals + Bootstrap Template.
 How to create simple search function using  ✔ Laravel 5 Tutorial : Simple Search Function Using GET Method in laravel 5.3

Simple Search Function Using GET Method in laravel 5.3

First, we will create Search Box in our view files (blog/index.blade.php)

index.blade.php

@extends('app')   @section('content')   <div class="form-group row add">     <div class="col-md-6">       <h1>Simple Laravel Ajax Crud</h1>     </div>     <div class="col-md-6">       {!! Form::open(['method'=>'GET','url'=>'blog','class'=>'navbar-form navbar-left','role'=>'search']) !!}       <div class="input-group custom-search-form">         <input type="text" name="search" class="form-control" placeholder="Search ....">         <span class="input-group-btn">           <button type="submit" class="btn btn-default-sm">             <i class="fa fa-search"></i>           </button>         </span>       </div>       {!! Form::close() !!}     </div>   </div>    <div class="form-group row add">     <div class="col-md-5">       <input type="text" class="form-control" id="title" name="title"       placeholder="Your title Here" required>       <p class="error text-center alert alert-danger hidden"></p>     </div>     <div class="col-md-5">       <input type="text" class="form-control" id="description" name="description"       placeholder="Your description Here" required>       <p class="error text-center alert alert-danger hidden"></p>     </div>     <div class="col-md-2">       <button class="btn btn-warning" type="submit" id="add">         <span class="glyphicon glyphicon-plus"></span> Add New Data       </button>     </div>   </div>    <div class="row">     <div class="table-responsive">       <table class="table table-borderless" id="table">         <tr>           <th>No.</th>           <th>Title</th>           <th>Description</th>           <th>Actions</th>         </tr>         {{ csrf_field() }}          <?php $no=1; ?>         @foreach($blogs as $blog)           <tr class="item{{$blog->id}}">             <td>{{$no++}}</td>             <td>{{$blog->title}}</td>             <td>{{$blog->description}}</td>             <td>             <button class="edit-modal btn btn-primary" data-id="{{$blog->id}}" data-title="✔ Laravel 5 Tutorial : Simple Search Function Using GET Method in laravel 5.3" data-description="{{$blog->description}}">               <span class="glyphicon glyphicon-edit"></span> Edit             </button>             <button class="delete-modal btn btn-danger" data-id="{{$blog->id}}" data-title="✔ Laravel 5 Tutorial : Simple Search Function Using GET Method in laravel 5.3" data-description="{{$blog->description}}">               <span class="glyphicon glyphicon-trash"></span> Delete             </button>           </td>           </tr>         @endforeach       </table>       {!! $blogs->links() !!}     </div>   </div>   <div id="myModal" class="modal fade" role="dialog">     <div class="modal-dialog">       <div class="modal-content">         <div class="modal-header">           <button type="button" class="close" data-dismiss="modal">&times;</button>             <h4 class="modal-title"></h4>         </div>         <div class="modal-body">           <form class="form-horizontal" role="form">             <div class="form-group">               <label class="control-label col-sm-2" for="id">ID :</label>               <div class="col-sm-10">                 <input type="text" class="form-control" id="fid" disabled>               </div>               </div>               <div class="form-group">               <label class="control-label col-sm-2" for="title">Title:</label>               <div class="col-sm-10">                 <input type="name" class="form-control" id="t">               </div>             </div>             <div class="form-group">             <label class="control-label col-sm-2" for="description">Description:</label>             <div class="col-sm-10">               <input type="name" class="form-control" id="d">             </div>           </div>           </form>             <div class="deleteContent">             Are you Sure you want to delete <span class="title"></span> ?             <span class="hidden id"></span>           </div>           <div class="modal-footer">             <button type="button" class="btn actionBtn" data-dismiss="modal">               <span id="footer_action_button" class='glyphicon'> </span>             </button>             <button type="button" class="btn btn-warning" data-dismiss="modal">               <span class='glyphicon glyphicon-remove'></span> Close             </button>           </div>         </div>       </div>     </div>   </div>   @stop 

Next, we will update our Blog Controller that is in index function

BlogController.php

public function index(){       // // we need to show all data from "blog" table       // $blogs = Blog::all();       // // show data to our view       // return view('blog.index',['blogs' => $blogs]);        $search = Request::get('search');       $blogs = Blog::where('title','like','%'.$search.'%')->orderBy('id')->paginate(6);       return view('blog.index',['blogs' => $blogs]);     } 

Video tutorial Create Search Function Using GET Method in laravel 5.3



Download full source code here https://goo.gl/y91XS9

see you next lessons ..
Sumber http://scqq.blogspot.com

Berlangganan update artikel terbaru via email:

0 Response to "✔ Laravel 5 Tutorial : Simple Search Function Using Get Method In Laravel 5.3"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel