Laravel:在路由上调用视图 vs 控制器
Laravel: calling the View on the Routes vs Controller
- 我想知道使用路由和
控制器? Laravel 的系统有很大的不同吗?
只是逻辑问题?
- 在路由上调用视图和在路由上调用视图有区别吗
在控制器上查看?
- Controller会自动缓存View而Routes不会吗?因为我在某处看到,如果我们在Controller中调用View,它会被缓存,但是如果我们调用Routes 中的 View,它不是,所以我们必须在 Routes 中手动缓存 View。 这是真的吗?
I want to know what are the differences between using Routes and Controller?
Is there a major difference in Laravel's system, or is it just a matter of logic?
路由是您声明应用程序 URL 的地方,控制器包含表示应用程序逻辑的代码。
您可以将代码放在路由声明的回调参数中
Route::get('/user', function () {
$user = User::where('active', '=', 1)
->where('parent_user_id', '=', Auth::id())
->paginate(10);
return view('users', ['users' => $user]);
});
但是很快就会变得很乱,所以最好声明一个控制器相关的路由class
Route::get('/user', [UserController::class, 'index']);
Is there a difference between calling the View on the Routes and the View on the Controller?Does the Controller automatically cache the View and Routes does not?Because I read somewhere that if we call the View in the Controller, it will be cached, but if we call the View in the Routes, it is not so we have to cache the View manually in the Routes. Is this true?
没有区别,除非与第三方缓存包相关,否则两者都不缓存。
Does the Controller automatically cache the View and Routes does not? Because I read somewhere that if we call the View in the Controller, it will be cached, but if we call the View in the Routes, it is not so we have to cache the View manually in the Routes. Is this true?
视图和路由由 Laravel 自动缓存。
视图缓存存在于:storage/framework/views
如果您想管理视图的缓存:
php artisan view:clear
php artisan view:cache
路由缓存存在于:bootstrap/cache/routes.php
如果你想管理路由的缓存:
php artisan route:clear
php artisan route:cache
- 我想知道使用路由和 控制器? Laravel 的系统有很大的不同吗? 只是逻辑问题?
- 在路由上调用视图和在路由上调用视图有区别吗 在控制器上查看?
- Controller会自动缓存View而Routes不会吗?因为我在某处看到,如果我们在Controller中调用View,它会被缓存,但是如果我们调用Routes 中的 View,它不是,所以我们必须在 Routes 中手动缓存 View。 这是真的吗?
I want to know what are the differences between using Routes and Controller? Is there a major difference in Laravel's system, or is it just a matter of logic?
路由是您声明应用程序 URL 的地方,控制器包含表示应用程序逻辑的代码。
您可以将代码放在路由声明的回调参数中
Route::get('/user', function () {
$user = User::where('active', '=', 1)
->where('parent_user_id', '=', Auth::id())
->paginate(10);
return view('users', ['users' => $user]);
});
但是很快就会变得很乱,所以最好声明一个控制器相关的路由class
Route::get('/user', [UserController::class, 'index']);
Is there a difference between calling the View on the Routes and the View on the Controller?Does the Controller automatically cache the View and Routes does not?Because I read somewhere that if we call the View in the Controller, it will be cached, but if we call the View in the Routes, it is not so we have to cache the View manually in the Routes. Is this true?
没有区别,除非与第三方缓存包相关,否则两者都不缓存。
Does the Controller automatically cache the View and Routes does not? Because I read somewhere that if we call the View in the Controller, it will be cached, but if we call the View in the Routes, it is not so we have to cache the View manually in the Routes. Is this true?
视图和路由由 Laravel 自动缓存。
视图缓存存在于:storage/framework/views
如果您想管理视图的缓存:
php artisan view:clear
php artisan view:cache
路由缓存存在于:bootstrap/cache/routes.php
如果你想管理路由的缓存:
php artisan route:clear
php artisan route:cache