【问题标题】:How to fix this Uncaught UnexpectedValueException: Invalid route action如何修复这个 Uncaught UnexpectedValueException: Invalid route action
【发布时间】: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

【问题讨论】:

  • 你能添加一些你用来打路线的代码

标签: php laravel-5 routes


【解决方案1】:

问题是因为您没有在路由定义中使用命名空间。将您的路线定义更改为:

Route::get('theme/{file?}', 'Core\Controllers\Assets\FuzzyController')->name('fuzzy-theme.get');

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2021-11-05
    • 2018-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-24
    • 1970-01-01
    • 1970-01-01
    • 2021-09-24
    相关资源
    最近更新 更多