Skip to content

Commit

Permalink
Search and pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
tibi2303 committed Jun 7, 2018
1 parent 84a6648 commit fc1f9e9
Show file tree
Hide file tree
Showing 9 changed files with 342 additions and 202 deletions.
18 changes: 14 additions & 4 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@

use Illuminate\Http\Request;
use App\User;
use Symfony\Component\Console\Input\Input;

class UserController extends Controller
{
public function listUser() {

$users = User::all();
public function listUsers() {

$users = User::paginate(10);

return $users;
}
public function searchUsers(Request $request) {

$query = $request->input('query');

$users = User::where('name','like','%'.$query.'%')->orWhere('email','like','%'.$query.'%')->paginate(10);

return $users;

return view('users', compact('users'));
}
}
17 changes: 3 additions & 14 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
use Notifiable;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
protected $table = 'users';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'role',
];
}
22 changes: 19 additions & 3 deletions database/seeds/userseeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,28 @@ public function run()
1 => 'user',
2 => 'guest'
];
for ($i=1; $i < 11; $i++) {
$emails = [
0 => 'admin',
1 => 'user',
2 => 'guest',
3 => 'john',
4 => 'anne',
5 => 'andrew',
];
$names = [
0 => 'admin',
1 => 'user',
2 => 'guest',
3 => 'john',
4 => 'anne',
5 => 'andrew',
];
for ($i=1; $i < 101; $i++) {
$users[] = [
'id' => $i,
'name' => str_random(10),
'name' => $names[rand(0,5)],
'role' => $roles[rand(0,2)],
'email' => str_random(10).'@gmail.com'
'email' => $emails[rand(0,5)] . str_random(2).'@gmail.com'
];
};
foreach ($users as $user) {
Expand Down
Loading

0 comments on commit fc1f9e9

Please sign in to comment.