1public function index(){
2 // // we need to show all data from "blog" table
3 // $blogs = Blog::all();
4 // // show data to our view
5 // return view('blog.index',['blogs' => $blogs]);
6
7 $search = Request::get('search');
8 $blogs = Blog::where('title','like','%'.$search.'%')->orderBy('id')->paginate(6);
9 return view('blog.index',['blogs' => $blogs]);
10 }
11
1 ->whereHas('translation', function ($query) use ($name){
2 $query->where('name', 'like', $name);
3 }, '>=', 10)
4
1$users = User::has('posts')->withCount('posts')->orderBy('posts_count')->take(50)->get();
2
3$userIndex = $users->search(function($user) {
4 return $user->id === Auth::id();
5});
1@extends('app')
2 @section('content')
3 <div class="form-group row add">
4 <div class="col-md-6">
5 <h1>Simple Laravel Ajax Crud</h1>
6 </div>
7 <div class="col-md-6">
8 {!! Form::open(['method'=>'GET','url'=>'blog','class'=>'navbar-form navbar-left','role'=>'search']) !!}
9 <div class="input-group custom-search-form">
10 <input type="text" name="search" class="form-control" placeholder="Search ....">
11 <span class="input-group-btn">
12 <button type="submit" class="btn btn-default-sm">
13 <i class="fa fa-search"></i>
14 </button>
15 </span>
16 </div>
17 {!! Form::close() !!}
18 </div>
19 </div>
20
21 <div class="form-group row add">
22 <div class="col-md-5">
23 <input type="text" class="form-control" id="title" name="title"
24 placeholder="Your title Here" required>
25 <p class="error text-center alert alert-danger hidden"></p>
26 </div>
27 <div class="col-md-5">
28 <input type="text" class="form-control" id="description" name="description"
29 placeholder="Your description Here" required>
30 <p class="error text-center alert alert-danger hidden"></p>
31 </div>
32 <div class="col-md-2">
33 <button class="btn btn-warning" type="submit" id="add">
34 <span class="glyphicon glyphicon-plus"></span> Add New Data
35 </button>
36 </div>
37 </div>
38
39 <div class="row">
40 <div class="table-responsive">
41 <table class="table table-borderless" id="table">
42 <tr>
43 <th>No.</th>
44 <th>Title</th>
45 <th>Description</th>
46 <th>Actions</th>
47 </tr>
48 {{ csrf_field() }}
49
50 <?php $no=1; ?>
51 @foreach($blogs as $blog)
52 <tr class="item{{$blog->id}}">
53 <td>{{$no++}}</td>
54 <td>{{$blog->title}}</td>
55 <td>{{$blog->description}}</td>
56 <td>
57 <button class="edit-modal btn btn-primary" data-id="{{$blog->id}}" data-title="{{$blog->title}}" data-description="{{$blog->description}}">
58 <span class="glyphicon glyphicon-edit"></span> Edit
59 </button>
60 <button class="delete-modal btn btn-danger" data-id="{{$blog->id}}" data-title="{{$blog->title}}" data-description="{{$blog->description}}">
61 <span class="glyphicon glyphicon-trash"></span> Delete
62 </button>
63 </td>
64 </tr>
65 @endforeach
66 </table>
67 {!! $blogs->links() !!}
68 </div>
69 </div>
70 <div id="myModal" class="modal fade" role="dialog">
71 <div class="modal-dialog">
72 <div class="modal-content">
73 <div class="modal-header">
74 <button type="button" class="close" data-dismiss="modal">×</button>
75 <h4 class="modal-title"></h4>
76 </div>
77 <div class="modal-body">
78 <form class="form-horizontal" role="form">
79 <div class="form-group">
80 <label class="control-label col-sm-2" for="id">ID :</label>
81 <div class="col-sm-10">
82 <input type="text" class="form-control" id="fid" disabled>
83 </div>
84 </div>
85 <div class="form-group">
86 <label class="control-label col-sm-2" for="title">Title:</label>
87 <div class="col-sm-10">
88 <input type="name" class="form-control" id="t">
89 </div>
90 </div>
91 <div class="form-group">
92 <label class="control-label col-sm-2" for="description">Description:</label>
93 <div class="col-sm-10">
94 <input type="name" class="form-control" id="d">
95 </div>
96 </div>
97 </form>
98 <div class="deleteContent">
99 Are you Sure you want to delete <span class="title"></span> ?
100 <span class="hidden id"></span>
101 </div>
102 <div class="modal-footer">
103 <button type="button" class="btn actionBtn" data-dismiss="modal">
104 <span id="footer_action_button" class='glyphicon'> </span>
105 </button>
106 <button type="button" class="btn btn-warning" data-dismiss="modal">
107 <span class='glyphicon glyphicon-remove'></span> Close
108 </button>
109 </div>
110 </div>
111 </div>
112 </div>
113 </div>
114 @stop
115