Skip to content

Instantly share code, notes, and snippets.

@aklimaruhina
Created February 25, 2023 12:35
Show Gist options
  • Save aklimaruhina/d77f1f8f35eb3fbd863c8a1b62b53c87 to your computer and use it in GitHub Desktop.
Save aklimaruhina/d77f1f8f35eb3fbd863c8a1b62b53c87 to your computer and use it in GitHub Desktop.
1. create controller
public function search(Request $request)
{
$query = $request->input('query');
$data = DB::table('my_table')
->where('column1', 'LIKE', '%' . $query . '%')
->orWhere('column2', 'LIKE', '%' . $query . '%')
->paginate(10);
return view('my_view', ['data' => $data, 'query' => $query]);
}
2.create form
<form action="{{ route('search') }}" method="GET">
<input type="text" name="query" value="{{ $query }}">
<button type="submit">Search</button>
</form>
3. table
<table>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
@foreach ($data as $item)
<tr>
<td>{{ $item->column1 }}</td>
<td>{{ $item->column2 }}</td>
</tr>
@endforeach
</tbody>
</table>
{{ $data->links() }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment