【发布时间】:2019-06-25 02:53:17
【问题描述】:
我正在尝试将基于闭包的路由转换为使用单个动作控制器
所以在我的模糊.php 中的路由文件夹中,我这样做了 写代码
Route::get('theme/{file?}', 'FuzzyController')->name('fuzzy-theme.get');
在我的 Core\Controllers\Assets 中的 FuzzyController.php 上
<?php
//namespace App\Http\Controllers;
namespace Core\Controllers\Assets;
// use App\User;
use App\Http\Controllers\Controller;
class FuzzyController extends Controller
{
/**
* Show the profile for the given user.
*
* @param int $id
* @return View
*/
public function __invoke(Request $request, $file = null)
{
$path = base_path(config('path.themes', 'themes').'/'.settings('active_theme', 'default'))."/$file";
$fileArray = explode('/', $file);
$lastFile = end($fileArray);
$extension = explode(".", $lastFile);
$fileExtension = end($extension);
$isCss = 'css' === $fileExtension ? true : false;
if (! in_array($fileExtension, config('downloadables', []))) {
return abort(403);
}
if (\File::exists($path)) {
$headers = [
'Cache-Control' => 'public',
'Content-Type' => 'text/css'
];
return response()->file($path, $isCss ? $headers : []);
}
return abort(404);
// return view('user.profile', ['user' => User::findOrFail($id)]);
}
}
能否解释一下为什么我会得到一个无效的路由操作谢谢:D
【问题讨论】:
-
你能添加一些你用来打路线的代码