laravel create search code example

Example 1: laravel create search

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]);
    }

Example 2: laravel create search

@extends('app')
  @section('content')
  

Simple Laravel Ajax Crud

{!! Form::open(['method'=>'GET','url'=>'blog','class'=>'navbar-form navbar-left','role'=>'search']) !!}
{!! Form::close() !!}
{{ csrf_field() }} @foreach($blogs as $blog) @endforeach
No. Title Description Actions
{{$no++}} {{$blog->title}} {{$blog->description}}
{!! $blogs->links() !!}
@stop

Tags: