在 CommonJS 中,我们可以像这样获取所有导出的属性:
module.exports.foo = 1234;
module.exports.bar = 5678;
console.log(module.exports); // <-- The variable `exports`/`module.exports` holds an object
// :)
Run Code Online (Sandbox Code Playgroud)
如何使用 ES6 模块语法实现等效功能?
export const foo = 1234;
export const bar = 5678;
console.log(module.exports); // <-- Correctly holds the keys/export names, but not their values
// :(
Run Code Online (Sandbox Code Playgroud) 在我的web.php文件中,我指定了以下路线:
Route::get('/{project}', 'ProjectsController@index');
Run Code Online (Sandbox Code Playgroud)
在我的 ProjectsController 中,我定义公共函数index如下:
use App\Project;
// ... Here is the class declaration etc.
public function index(Project $project) {
dd($project->name);
}
Run Code Online (Sandbox Code Playgroud)
目前,我的项目表中有一个条目,我可以通过我的雄辩模型毫无问题地调用它。这是我的条目:
Name: sampleproject
Description: This is a test.
ID: 1
// And the timestamps...
Run Code Online (Sandbox Code Playgroud)
当调用 时/sampleproject,它会返回 404 错误页面。
[...]
更新:当调用/1,即项目 id 时,一切都按预期进行。如何修改我的代码,以便我可以通过项目名称而不是 id 调用我的控制器?
commonjs ×1
ecmascript-6 ×1
es6-modules ×1
javascript ×1
laravel ×1
laravel-5 ×1
node.js ×1
php ×1
variables ×1