我有时想连接到另一个数据库.
我用数据库连接数据创建了一个config.php.
但是我怎么能告诉laravel连接到这个使用config/database.php的数据库呢?
例如,当使用Schema该类时.
因为似乎没有人理解我想要的东西.
我不想使用config/database.php,我想在不同的位置使用不同的配置文件.
目前我需要验证这样的每个表单:
$(document).ready(function () {
$('#admin_settings_general').validate({
rules: {
admin_settings_application_title: {
required: true
}
},
highlight: function (element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function (element) {
$(element).closest('.form-group').removeClass('has-error');
}
});
});
Run Code Online (Sandbox Code Playgroud)
我希望它能自动验证带有required 标签的每个元素的表单.
我怎样才能做到这一点?
我正在将面板从使用 SQL 语法(从 InfluxDB 版本 1.X)迁移到新的 influx 语法(InfluxDB 版本 2)。
数据标签存在问题。它包括我用来过滤它的属性。例如,如果我从包含 2 天的范围中选择数据,它会将数据拆分。请参阅下面的屏幕截图:
这完全把图表弄乱了。基本代码如下所示:
from(bucket: "main")
|> range(start: v.timeRangeStart, stop:v.timeRangeStop)
|> filter(fn: (r) =>
r._measurement == "POWER" and
r._field == "value" and
r.device == "living_room"
)
|> aggregateWindow(every: v.windowPeriod, fn: sum)
Run Code Online (Sandbox Code Playgroud)
显然应该只是“POWER”和“CURRENT”。
我尝试了十几种不同的方法,但无法提出可行的解决方案。
例如,如果我这样做:
from(bucket: "main")
|> range(start: v.timeRangeStart, stop:v.timeRangeStop)
|> filter(fn: (r) =>
r._measurement == "POWER" and
r._field == "value" and
r.device == "living_room"
)
|> aggregateWindow(every: v.windowPeriod, fn: sum)
|> map(fn: (r) => ({ POWER: r._value }))
Run Code Online (Sandbox Code Playgroud)
它说“数据没有时间字段”。 …
我有一个带有此签名的命令
order:check {--order}
Run Code Online (Sandbox Code Playgroud)
并执行此:
php artisan order:check --order 7
Run Code Online (Sandbox Code Playgroud)
由于某种原因导致此异常
[RuntimeException]
Too many arguments, expected arguments "command".
Run Code Online (Sandbox Code Playgroud)
为什么?我希望这个命令既可以作为php artisan order:check可选订单ID 执行,也可以使用可选订单ID执行php artisan order:check --order X
我有一个令人讨厌的问题.我的Laravel 5应用程序非常慢,完全加载需要1-3秒,这是不可容忍的.
经过几个小时的调试,我发现问题是Auth::user(),更具体地说,当你尝试访问类似的东西时Auth::user()->username.
我注意到的Auth::user()->id是:快速闪耀,Auth::user()->username需要1-3秒.它也似乎没有与mySQL服务器有什么东西,因为正在执行完全相同的查询,无论我是否使用->id或->username.
它不仅在使用时->username很慢,而且除了->id访问角色之外,对于几乎所有的东西来说似乎都很慢Auth::user()->roles.
如果重要,我使用Entrust进行许可/角色管理.
用户模型:
<?php namespace App\Models;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Zizaco\Entrust\Traits\EntrustUserTrait;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use Authenticatable, CanResetPassword, EntrustUserTrait, SoftDeletes;
protected $table = 'users';
protected $guarded = ['id'];
protected $fillable = ['username', 'email', 'activation_code'];
protected $hidden = ['password', 'remember_token'];
protected $dates …Run Code Online (Sandbox Code Playgroud) 我需要在某些条件下加载另一个名为.env.test的 .env 文件。
我尝试通过添加中间件来做到这一点
app()->loadEnvironmentFrom('.env.test');
Dotenv::create(base_path(), '.env.test')->overload();
Run Code Online (Sandbox Code Playgroud)
到Kernel.phpbootstrap()的方法。我还尝试为此创建一个专用中间件并将其加载为Web中间件组中的第一个中间件。但无论哪种方式,它都会加载标准 .env 文件。
如果我在/bootstrap/app.php文件中执行它,它就可以工作,但我真的不想把它放在那里。
如何在 Laravel 之外仅使用 PHP 解密已使用 Laravel 4 Encrypt 类加密的字符串?
我有点卡住了ConfigParser.
我想为现有部分添加特定设置.
我做:
import ConfigParser
Config = ConfigParser.ConfigParser()
Config
Config.read("/etc/yum.repos.d/epel.repo")
Config.sections()
Config.set('epel','priority',10)
with open('/etc/yum.repos.d/epel.repo', 'w') as fout:
Run Code Online (Sandbox Code Playgroud)
然后它显示:
...
File "<stdin>", line 2
^
IndentationError: expected an indented block
>>>
Run Code Online (Sandbox Code Playgroud)
编辑#1
现在我尝试使用iniparse模块.我做了:
from iniparse import INIConfig
cfg = INIConfig(open('/etc/yum.repos.d/epel.repo'))
cfg.epel.priority=10
f = open('/etc/yum.repos.d/epel.repo', 'w')
print >>f, cfg
f.close()
Run Code Online (Sandbox Code Playgroud)
不幸的是,它删除了旧内容.我怎么解决这个问题?
编辑#2
看起来它现在有效.
f = open('/etc/yum.repos.d/epel.repo', 'wb')
Run Code Online (Sandbox Code Playgroud)
做了伎俩.
似乎不可能自己捕获错误,因为得到了laravel 4错误输出.
例如,如果我尝试:
$databaseConfig = Config::get('database.connections.mysql');
$connect = mysql_connect($databaseConfig['host'], $databaseConfig['username'], $databaseConfig['password']);
if (!$connect)
{
return 'error';
}
Run Code Online (Sandbox Code Playgroud)
如果发生错误,我将不会得到"错误",insted laravel向我显示异常(在该橙色站点上).
如果你继续尝试一下,也一样
try {
$pdo = DB::connection('mysql')->getPdo();
}
catch(PDOException $exception) {
return Response::make('Database error! ' . $exception->getCode());
}
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
如何从laravel读取配置文件?例如,对于数据库连接(app/config/database/.php)
我想从配置中获取mysql数据.
对于一个包你可以这样做:
return Config::get('package::group.option');
Run Code Online (Sandbox Code Playgroud)
但是如何为主文件做到这一点?