如何在Laravel 5中定义日志文件的最大数量.我使用每日日志轮换,并且我在存储中只有"5"日志文件,我想要过去30天,但我不知道该怎么做这个,我没有发现任何线索.
这是一个VueJS组件:
<template>
<a @click="log">click me<a>
</template>
<script>
export default {
data() {
return {
a: "a",
b: "something",
foo: { bar: "baz" },
// etc.
}
},
methods: {
log() {
// console.log( data );
// ???
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
我想data从log函数中访问它并将其作为对象获取(就像在其声明中一样).我知道我可以得到这样的数据:
log() {
console.log( this.a );
console.log( this.b );
console.log( this.foo );
}
Run Code Online (Sandbox Code Playgroud)
但我想要的是整个数据作为对象(因为我想通过事件将数据发送到父组件).
有没有办法将整个数据对象放在组件的方法中?
A User有一个(或零)Company,一个Company属于一个且只有一个User.我尝试为用户保存公司,但每次重新触发保存方法时,它都会在数据库中添加一个新条目.这是一对一的关系,所以我通过save方法User.
所以,Company有一个方法user():
public function user() {
return $this->belongsTo(User::class, 'user_id');
}
Run Code Online (Sandbox Code Playgroud)
并User有一种方法company():
public function company() {
return $this->hasOne(Company::class, 'user_id');
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试保存(如此创建或更新)这样的用户公司(在Controller中):
$company = new Company();
$company->name = 'Test';
User::findOrFail(1)->company()->save($company);
Run Code Online (Sandbox Code Playgroud)
我第一次运行此代码时会在数据库中创建条目(OK),但第二次为同一用户添加新条目(不正常).我以为它只会更新数据库条目.
在Laravel中,这是一个小问题(或者我在一对一关系中不理解的事情),还是我做错了什么?(我想并希望这是第二个目的)
我不能使用v-model文件输入,Vue说我必须使用v-on:change.好的,我可以使用v-on:change,但是如何将输入文件的"内容"绑定到data属性?
假设我想将它绑定到组件中this.file:
export default {
data() {
file: null
},
// ...
}
Run Code Online (Sandbox Code Playgroud)
这是HTML部分:
<input id="image" v-on:change="???" type="file">
<!-- ^- don't know how to bind without v-model -->
Run Code Online (Sandbox Code Playgroud)
我该怎么做绑定?
我在Laravel 5(barryvdh/laravel-cors)中使用了全局中间件,但我只希望它在一个环境(dev)上运行.那是因为我只需要在开发环境中使用composer,因此它不会安装在生产环境中.
我注册了它在App Kernel中有一个全局中间件,所以如果我尝试在production(Class 'Barryvdh\Cors\CorsServiceProvider' not found)中部署我的应用程序,我会出错.我知道为什么,但我正在寻找解决方案.
有没有办法在laravel 5中全局声明中间件,但只在一个环境中需要?
我希望它足够清楚,如果不是我可以编辑我的帖子:)
我尝试在Mac OS X 10.11.2上为Rust安装Iron框架,但是当我运行cargo build或cargo run编译时它失败了openssl:
failed to run custom build command for `openssl-sys-extras v0.7.4`
Process didn't exit successfully: `/xxx/rust/hello/target/debug/build/openssl-sys-extras-413d6c73b37a590d/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("x86_64-apple-darwin")
debug=true opt-level=0
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CC_x86_64-apple-darwin = None
CC_x86_64_apple_darwin = None
HOST_CC = None
CC = None
HOST = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
CFLAGS_x86_64-apple-darwin = …Run Code Online (Sandbox Code Playgroud) 我从这个Rust代码创建了一个小的WASM文件:
#[no_mangle]
pub fn hello() -> &'static str {
"hello from rust"
}
Run Code Online (Sandbox Code Playgroud)
它构建并且hello可以从JS调用该函数:
<!DOCTYPE html>
<html>
<body>
<script>
fetch('main.wasm')
.then(response => response.arrayBuffer())
.then(bytes => WebAssembly.instantiate(bytes, {}))
.then(results => {
alert(results.instance.exports.hello());
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的问题是alert显示"未定义".如果我返回a i32,它可以工作并显示i32.我也尝试返回String但是它不起作用(它仍然显示"未定义").
有没有办法从WebAssembly中的Rust返回一个字符串?我应该使用什么类型的?
有没有办法在路由中间添加可选参数?
示例路线:
/things/entities/
/things/1/entities/
Run Code Online (Sandbox Code Playgroud)
我试过这个,但它不起作用:
get('things/{id?}/entities', 'MyController@doSomething');
Run Code Online (Sandbox Code Playgroud)
我知道我能做到这一点......
get('things/entities', 'MyController@doSomething');
get('things/{id}/entities', 'MyController@doSomething');
Run Code Online (Sandbox Code Playgroud)
...但我的问题是: 我可以在路线中间添加可选参数吗?
我有一个get_url_content功能,不关心错误(这只是一个测试).它返回一个Option<String>.
extern crate hyper;
use std::io::Read;
use hyper::client::Client;
fn get_url_content(url: &str) -> Option<String> {
let client = Client::new();
let mut s = String::new();
match client.get(url).send() {
Ok(mut res) => {
match res.read_to_string(&mut s) {
Ok(_) => {
Some(s)
},
Err(_) => {
None
}
}
},
Err(_) => {
None
}
}
}
Run Code Online (Sandbox Code Playgroud)
这个功能很好但我发现它不容易阅读.我认为有一些关于此类案例的最佳实践,以使其更具可读性.嵌套匹配是不好的做法(比如JS中的回调地狱),如果是这样,如何避免它?
运行Laravel Dusk时有没有办法获得代码覆盖?
我知道它运行浏览器测试,所以它不是仔细检查代码,但有没有办法添加一个监听器来检查所涵盖的代码?我现在没有看到关于这个主题的任何内容.
laravel ×5
php ×4
laravel-5 ×3
rust ×3
javascript ×2
vue.js ×2
vuejs2 ×2
composer-php ×1
eloquent ×1
laravel-5.4 ×1
laravel-dusk ×1
macos ×1
phpunit ×1
rust-cargo ×1
webassembly ×1