小编Eru*_*iel的帖子

只有数字.React中的输入数字

尝试从输入中排除减号和加号,但它出错了

handleChange(event) {
  const value = event.target.value.replace(/\+|-/ig, '');
  this.setState({financialGoal: value});
}
Run Code Online (Sandbox Code Playgroud)

渲染输入代码

<input style={{width: '150px'}} type="number" value={this.state.financialGoal} onChange={this.handleChange}/>
Run Code Online (Sandbox Code Playgroud)

javascript regex reactjs

27
推荐指数
7
解决办法
7万
查看次数

在 Laravel 5.7 的子域组中设置命名路由

我一直在开发一个多租户应用程序,我正在尝试根据文档在子域中设置路由:https : //laravel.com/docs/5.7/routing#route-group-sub-domain -路由

在我的web.php路由文件中,我有这样的东西:

Route::domain('{account}.example.test')->group(function () {        
    Route::get('/home', 'HomeController@index')->name('home');        
});
Run Code Online (Sandbox Code Playgroud)

现在,问题是在刀片中使用命名路由,但我想我最终可能会在我的控制器中遇到同样的问题。

每当我尝试使用这样的命名路由时:

刀片代码

<a href="{{ route('home') }}">Home</a>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

缺少 [Route: home] [URI: home] 的必需参数。(查看:/home/vagrant/Code/example/resources/views/example.blade.php)

我找到了解决这个问题的方法,你只需要:

<a href="{{ route('home', request('account')) }}">Home</a>
Run Code Online (Sandbox Code Playgroud)

我还使用助手“解决”了这个问题......

<a href="{{ route('home') }}">Home</a>
Run Code Online (Sandbox Code Playgroud)

所以我可以像这样使用它:

<a href="{{ acctRoute('home') }}">Home</a>
Run Code Online (Sandbox Code Playgroud)

但我仍然想知道是否有更干净的方法来做到这一点,也许使用一些总是注入参数的中间件?

php laravel laravel-routing laravel-5

3
推荐指数
1
解决办法
2661
查看次数

Laravel 使用 Sum 和 Groupby

我想获取每个月的数量总和,以便我可以在条形图上按月显示数量

这是我想的但没有锻炼

 $data1 = Borrow::groupBy(function($d) {
 return Carbon::parse($d->created_at)->format('m')->sum('quantity');
 })->get();
Run Code Online (Sandbox Code Playgroud)

我的表结构

Schema::create('borrows', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('member_id');
        $table->integer('book_id');
        $table->integer('quantity');
        $table->integer('status')->default(0);
        $table->timestamps();
    });
Run Code Online (Sandbox Code Playgroud)

php laravel eloquent laravel-collection laravel-5.6

2
推荐指数
1
解决办法
8267
查看次数