我有这条路线:
Route::get('/MyModel/{id}', 'MyController@show');
Run Code Online (Sandbox Code Playgroud)
该方法show()接受一个被调用的参数id,我想设置一个别名,/MyModel/1以便它可以访问/MyCustomURL.
我已经尝试过几种组合,比如:
Route::get('/MyCustomURL', ['uses' => 'MyController@show', 'id' => 1]);
Run Code Online (Sandbox Code Playgroud)
但我不断错过方法所需的参数错误show().
在Laravel有没有一个干净的方法来实现这一目标?
我正在尝试向类添加自定义断言,TestReponse以便我可以做这样的事情:
$response = $this->json('POST', '/foo/bar');
$response->myCustomAssertion();
Run Code Online (Sandbox Code Playgroud)
我尝试创建一个App\TestResponse扩展原始类的类,然后将其绑定到App\Provider\AppServiceProvider类中。
public function register()
{
$this->app->bind('Illuminate\Foundation\Testing\TestResponse', function ($app) {
return new App\TestResponse();
});
}
Run Code Online (Sandbox Code Playgroud)
但$response->json()仍然返回原来的一个而不是我自己的实现。
如何扩展TestResponse课程?
一直在尝试 Webpack 的 5 Module Federation 并遇到了这个问题。尝试了很多方法,但似乎都不起作用。基本上,当我尝试styled-components在联合模块上使用时,我收到 React 的Invalid hook call错误。
这是一个试图重现问题的存储库:
我想知道我是否遗漏了什么,或者这是否是某种错误。
我是 Laravel 的新手,并试图将产品从管理面板添加到索引页面,首先它运行良好,但现在显示错误SQLSTATE[HY000]: General error: 1364 Field 'care' doesn't have a default value,是否有解决此问题的方法?
SQLSTATE[HY000]: General error: 1364 Field 'care' doesn't have a
default value (SQL: insert into `products` (`product_name`,
`product_code`, `product_color`, `description`, `price`, `image`,
`updated_at`, `created_at`) values (Filter, ASD111, CLR, ASDF, 1000,
85525.png, 2019-01-10 17:18:33, 2019-01-10 17:18:33))
Run Code Online (Sandbox Code Playgroud)
这是 ProductsController:
public function addProduct(Request $request){
if($request->isMethod('post')){
$data = $request->all();
//echo "<pre>"; print_r($data); die;
$product = new Product;
$product->product_name = $data['product_name'];
$product->product_code = $data['product_code'];
$product->product_color = $data['product_color'];
if(!empty($data['description'])){
$product->description = $data['description']; …Run Code Online (Sandbox Code Playgroud) 假设我有这样的背景:
export const ThemeContext = createContext();
export function ThemeWrapper({ children }) {
const sharedState = {
darkMode: false,
};
return (
<ThemeContext.Provider value={sharedState}>
{children}
</ThemeContext.Provider>
);
}
export function useThemeContext() {
return useContext(ThemeContext);
}
Run Code Online (Sandbox Code Playgroud)
_document.js我可以这样访问:
import Document, { Html, Head, Main, NextScript } from "next/document";
import { ThemeWrapper, ThemeContext } from "../context/theme";
class MyDocument extends Document {
static contextType = ThemeContext;
render() {
console.log("theme", this.context);
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
} …Run Code Online (Sandbox Code Playgroud) 我试图将类型为string的数据传递给构造,以确保始终传递字符串
在我的重置密码类中,我有
class RequestResetPassword extends Mailable
{
public function __construct(User $user, String $resettoken)
{
}
Run Code Online (Sandbox Code Playgroud)
用户部分是可以的,因为它是用户模型类型,但我如何通过声明它必须始终是一个字符串来访问访问令牌部分
以上产生错误
App string not found.
Run Code Online (Sandbox Code Playgroud) 我收到此错误:
数据库(宅基地)不存在。
当我尝试这个简单的黄昏测试时:
class ShowArticleTest extends DuskTestCase
{
use DatabaseMigrations;
/** @test */
public function it_shows_all_articles()
{
Article::create([
'title' => 'My First Article',
'body' => 'Some body text.'
]);
$this->browse(function (Browser $browser) {
$browser->visit('/articles')
->assertSee('My First Article');
});
}
}
Run Code Online (Sandbox Code Playgroud)
我可以在堆栈跟踪中看到错误来自处理请求的控制器方法/articles,如下所示:
public function all()
{
Article::all();
}
Run Code Online (Sandbox Code Playgroud)
因此,测试本身似乎可以访问数据库,但控制器不能访问数据库。
该.env.dusk.local文件如下所示:
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Run Code Online (Sandbox Code Playgroud)
该homestead文件正在我的项目根文件夹中创建。该文件也在虚拟机内找到,权限如下所示:
-rw-rw-r-- 1个流浪者
尝试设置DATABASE为database/testing.sqlitein .env.dusk.local。Dusk 启动后会创建该文件,但错误仍然表明找不到数据库database/testing.sqlite。
数据库(database/testing.sqlite)不存在。
可以使用 CLI 访问数据库文件sqlite3,并且可以毫无问题地查询记录。 …
我使用以下方法设置了一个基本的可发布库@nrwl/react:
nx g @nrwl/react:lib my-new-lib --publishable --importPath=@myorg/my-new-lib
Run Code Online (Sandbox Code Playgroud)
然后在 monorepo 根目录中安装 MUI:
npm install @mui/material @emotion/react @emotion/styled
Run Code Online (Sandbox Code Playgroud)
并导入了一个MUI组件:
nx g @nrwl/react:lib my-new-lib --publishable --importPath=@myorg/my-new-lib
Run Code Online (Sandbox Code Playgroud)
最后我使用以下方法构建库:
nx run my-new-lib:build
Run Code Online (Sandbox Code Playgroud)
这是生成的package.json:
{
"name": "@myorg/my-new-lib",
"version": "0.0.1",
"module": "./index.js",
"main": "./index.js",
"type": "module",
"types": "./index.d.ts"
}
Run Code Online (Sandbox Code Playgroud)
MUI 依赖项不会添加到生成的package.json.
我缺少什么?
如果您想尝试的话,这里有一个存储库:
我使用的是Voyager,我想解决,如果用户是admin,请在欢迎页面中查看另一个菜单项。
预先感谢您的回答!
<body>
<div class="flex-center position-ref full-height">
@if (Route::has('login'))
<div class="top-right links">
@auth
<a href="{{ url('/home') }}">Home</a>
@else
<a href="{{ route('login') }}">Login</a>
<a href="{{ route('register') }}">Register</a>
@endauth
</div>
@endif
<div class="content">
<div class="title m-b-md">
Laravel
</div>
<div class="links">
<a href="https://laravel.com/docs">Documentation</a>
<a href="https://laracasts.com">Laracasts</a>
<a href="https://laravel-news.com">News</a>
<a href="https://forge.laravel.com">Forge</a>
<a href="https://github.com/laravel/laravel">GitHub</a>
</div>
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud) php ×6
laravel ×5
javascript ×2
laravel-5 ×2
reactjs ×2
eloquent ×1
laravel-5.4 ×1
laravel-dusk ×1
monorepo ×1
next.js ×1
npm ×1
nrwl-nx ×1
phpunit ×1
roles ×1
sqlite ×1
tailwind-css ×1
voyager ×1
webpack ×1