In the Laravel framework, resource routes and their corresponding resource controllers are notoriously limited in flexibility, so it’s best to avoid them. There’s no silver bullet here—you might think they save you time upfront, but customizing them can become a headache. It’s often better to skip them altogether from the start and implement routes and controllers tailored to your specific needs.
尽量不要使用资源路由和资源控制器
Laravel框架中,资源路由和对应的资源控制器扩展性太差,尽量别用。没有银弹,你以为你能偷到懒,但其实资源路由和资源控制器定制起来可麻烦了,不如一开始就不要使用它们。
安装中文语言包composer require “overtrue/laravel-lang:~6.0″后,在浏览器刷新页面报错Call to undefined method Illuminate\Translation\FileLoader::loadPath()
我的Laravel版本是10,报错原因是overtrue/laravel-lang:~6.0与Laravel 10不兼容,composer require “overtrue/laravel-lang”输出一条警告说:
Package overtrue/laravel-lang is abandoned, you should avoid using it.
在Laravel 10我们应该使用laravel-lang/lang语言包。因此这个报错的解决方法是,先移除overtrue/laravel-lang:~6.0包:
composer remove overtrue/laravel-lang
再安装laravel-lang/lang语言包:
composer require laravel-lang/lang
安装好了后,执行以下命令添加中文语言包到Laravel 10:
php artisan lang:add zh_CN
我们可以看到在resources/lang目录里增加了zh_CN.json文件和zh_CN文件夹。
然后修改config/app.php,找到’locale’ => ‘en’,改为’locale’ => ‘zh_CN’。
刷新浏览器看看。
更多laravel-lang/lang语言包的用法,例如如何添加多个语言包到Laravel、如何在“语言.json”文件里增加自定义的条目等,请查看laravel-lang/lang语言包的官方文档:Getting Started | Laravel Lang (laravel-lang.com)
参考
composer安装Laravel 11报错:laravel/framework[v11.9.0, …, v11.23.3] require fruitcake/php-cors ^1.3 -> found fruitcake/php-cors[dev-feat-setOptions, dev-master, dev-maincomposer…
我在使用composer安装Laravel 11的时候,遇到如下错误:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- laravel/framework[v11.9.0, ..., v11.23.3] require fruitcake/php-cors ^1.3 -> found fruitcake/php-cors[dev-feat-setOptions, dev-master, dev-main, dev-test-8.2, v0.1.0, v0.1.1, v0.1.2, v1.0-alpha1, ..., 1.2.x-dev (alias of dev-master)] but it does not match the constraint.
- Root composer.json requires laravel/framework ^11.9 -> satisfiable by laravel/framework[v11.9.0, ..., v11.23.3].
原因是阿里云composer镜像源中没有fruitcake/php-cors包的最新版。
解决方法是,切换回默认的composer镜像源:
composer config -g --unset repos.packagist
执行composer install
就安装成功了,不再报错。
参考