Skip to content

Commit 9da54b1

Browse files
author
qiang.sun
committed
基于Bootstrap+Vue实现异步分页功能
1 parent e2a1024 commit 9da54b1

File tree

14 files changed

+1554
-818
lines changed

14 files changed

+1554
-818
lines changed

app/Http/Controllers/OrderController.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

app/Http/Controllers/PostController.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Post;
56
use Illuminate\Http\Request;
7+
use Illuminate\Pagination\UrlWindow;
68

79
class PostController extends Controller
810
{
@@ -13,7 +15,7 @@ class PostController extends Controller
1315
*/
1416
public function index()
1517
{
16-
return 'All Posts';
18+
return view('post.index');
1719
}
1820

1921
/**
@@ -81,4 +83,23 @@ public function destroy($id)
8183
{
8284
//
8385
}
86+
87+
public function fetch()
88+
{
89+
// 每页显示6篇文章,如果页码太多,当前页码左右只显示2个页码
90+
$posts = Post::paginate(3)->onEachSide(2)->withPath(url('post'));
91+
// 处理页码及对应分页URL(页码过多,部分页码省略)
92+
$window = UrlWindow::make($posts);
93+
$pages = array_filter([
94+
$window['first'],
95+
is_array($window['slider']) ? '...' : null,
96+
$window['slider'],
97+
is_array($window['last']) ? '...' : null,
98+
$window['last'],
99+
]);
100+
return response()->json([
101+
'paginator' => $posts,
102+
'elements' => $pages
103+
]);
104+
}
84105
}

app/Http/Controllers/QueryController.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use App\Tag;
1111
use App\User;
1212
use App\UserProfile;
13+
use Faker\Generator;
1314
use Illuminate\Http\Request;
1415
use Illuminate\Support\Facades\Auth;
1516
use Illuminate\Support\Facades\DB;
@@ -87,6 +88,9 @@ public function where()
8788

8889
//dd($posts);
8990

91+
$res = DB::select('select round(avg(views), 2) as views from posts');
92+
dd($res);
93+
9094
return view('welcome');
9195
}
9296

@@ -362,10 +366,19 @@ public function relationship()
362366

363367
//$post->tags()->detach($tag->id);
364368

365-
$comment = Comment::with('commentable')->findOrFail(31);
366-
$comment->content = 'Laravel学院致力于提供优质Laravel中文学习资源';
367-
$comment->save();
369+
// $comment = Comment::with('commentable')->findOrFail(31);
370+
// $comment->content = 'Laravel学院致力于提供优质Laravel中文学习资源';
371+
// $comment->save();
372+
373+
//return $comment;
374+
$posts = Post::all();
375+
$faker = \Faker\Factory::create();
376+
foreach ($posts as $post) {
377+
$title = $faker->sentence;
378+
$post->title = trim($title, '.');
379+
$post->save();
380+
}
368381

369-
return $comment;
382+
return 'success';
370383
}
371384
}

app/Http/Controllers/UserController.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

app/Providers/AppServiceProvider.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ public function boot()
2929
{
3030
view()->share('siteName', 'Laravel学院');
3131
view()->share('siteUrl', 'https://laravelacademy.org');
32-
33-
Cache::extend('mongo', function ($app) {
34-
return new Repository(new MongoStore());
35-
});
3632
}
3733

3834
/**
@@ -45,24 +41,5 @@ public function register()
4541
if ($this->app->isLocal()) {
4642
$this->app->register(TelescopeServiceProvider::class);
4743
}
48-
49-
$this->app->bind(UserRepositoryInterface::class, function ($app) {
50-
return new UserRepository();
51-
});
52-
53-
// 延迟实例化
54-
$this->app->bind(BillerInterface::class, function ($app) {
55-
return new StripeBiller($app->make(BillingNotifierInterface::class));
56-
});
57-
58-
// 立即实例化
59-
//$this->app->bind(BillingNotifierInterface::class, StripeBiller::class);
60-
61-
$notifier = new SmsBillingNotifier;
62-
$this->app->instance(BillingNotifierInterface::class, $notifier);
63-
64-
$this->app->bind(OrderRepositoryInterface::class, function ($app) {
65-
return new DummyOrderRepository();
66-
});
6744
}
6845
}

app/Providers/AuthServiceProvider.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ public function boot()
2525
{
2626
$this->registerPolicies();
2727

28-
$this->app->singleton('auth', function ($app) {
29-
30-
});
3128
//
3229
}
3330

app/Providers/EventPusherServiceProvider.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ class EventPusherServiceProvider extends ServiceProvider
1313
{
1414
public function register()
1515
{
16-
$this->app->singleton(PusherSdkInterface::class, function ($app) {
17-
return new Pusher('app-key', 'secret-key', 'app-id');
18-
});
1916

20-
$this->app->singleton(EventPusherInterface::class, PusherEventPusher::class);
2117
}
2218
}

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"type": "project",
77
"require": {
88
"php": "^7.1.3",
9-
"barryvdh/laravel-debugbar": "^3.2",
109
"doctrine/dbal": "^2.8",
1110
"fideloper/proxy": "^4.0",
1211
"laravel/framework": "5.7.*",

0 commit comments

Comments
 (0)