我想使用laravel发送确认电子邮件.laravel Mail :: send()函数似乎只接受系统上文件的路径.问题是我的mailtemplates存储在数据库中,而不是存储在系统上的文件中.
如何将纯文本内容传递给电子邮件?
例:
$content = "Hi,welcome user!";
Mail::send($content,$data,function(){});
Run Code Online (Sandbox Code Playgroud) 我有一个用于图像上传的表单字段,我打开'files'=> true,如下所示:
{{ Form::label('image', 'Image') }}
{{ Form::file('image') }}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我想检查文件是否已上传并对其执行操作:
if (Input::hasFile('image')){
$in_path = 'img/';
$in_extension = Input::file('image')->getClientOriginalExtension();
$filename = Input::get('name').".".$in_extension;
Input::file('image')->move($in_path, $filename);
$user->image = $filename;
}
Run Code Online (Sandbox Code Playgroud)
但Input::hasFile总是返回假,我不知道为什么.
Input::file('image');
Run Code Online (Sandbox Code Playgroud)
结果是:
Symfony\Component\HttpFoundation\File\UploadedFile Object
(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => test.JPG
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => application/octet-stream
[size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 1
[pathName:SplFileInfo:private] =>
[fileName:SplFileInfo:private] =>
)
Run Code Online (Sandbox Code Playgroud)
我已经为另一个用户测试了另一张图片,这很好用.我不明白为什么这对一些用户和其他一些用户不起作用.
是否有某种图片不被接受?
还有哪些其他来源可能是导致这个问题的原因?
我正在尝试使用以下命令构建 go 包:
CGO_ENABLED=0 GOOS=linux go build -o bin/router -installsuffix cgo -ldflags '-w'
Run Code Online (Sandbox Code Playgroud)
在我的电脑上,这大约需要 0.5 秒。在 docker 容器中执行相同的命令需要 45 秒。
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/router -installsuffix cgo -ldflags '-w' /build/src/global/router
Run Code Online (Sandbox Code Playgroud)
本地我有 go 版本1.12.9 linux/amd64。docker 容器使用golang:1.13镜像作为基础。
我的猜测是,docker 构建过程的可用 CPU 较少,但这会产生这么大的差异吗?导致此问题的原因可能是什么?
这可以用一个最小的例子来重现:
main.go:
package main
import "log"
func main() {
log.Println("test")
}
Run Code Online (Sandbox Code Playgroud)
Dockerfile:
FROM golang:1.13
ADD main.go .
RUN CGO_ENABLED=0 GOOS=linux go build -o main -installsuffix cgo -ldflags '-w'
CMD [ "main" ]
Run Code Online (Sandbox Code Playgroud)
docker …
我正在使用Node v10.11.0,并且正在从Ubuntu 18.04运行此脚本。
我的文件设置如下所示:
main.js
import Login from './Login.mjs';
class Main {
constructor() {
const login = new Login();
login.login();
}
}
new Main();
Run Code Online (Sandbox Code Playgroud)
Login.mjs
import readline from 'readline';
class Login {
constructor() {
this.username = '';
this.password = '';
this.readline = readline.createInterface({
input: process.stdin,
output: process.stdout
});
}
login() {
this.readline.question('What is your username?', answer => {
this.username = answer;
});
this.readline.question('What is your password?', answer => {
this.password = answer;
});
}
}
export default Login;
Run Code Online (Sandbox Code Playgroud)
我main.js …
我有一个运行 5.6 版的 Laravel 项目。连接的数据库是带有 jenssegers/mongodb 包的 mongodb。
我编写了一个单元测试来测试与用户相关的功能。
该测试在配置的测试 mongodb 数据库中创建新用户。我想在每次测试运行后刷新数据库,所以我使用了RefreshDatabaseTrait。
使用RefreshDatabaseTrait 时,我在运行测试时收到以下错误:
有 1 个错误:
1) Tests\Unit\UserTest::it_gets_top_user 错误:在 null 上调用成员函数 beginTransaction()
当不使用 Trait 时,测试会在数据库中创建所有必要的内容并执行断言而不会出错。
测试看起来像这样:
/** @test */
public function it_gets_top_user()
{
factory(\App\Users\User::class, 5)->create();
$userOne = factory(\App\Users\User::class)->create([
'growth' => 10
]);
$topUser = Users::getTopUser();
$collection = new Collection();
$collection->push($userOne);
$this->assertEquals($collection, $topUser);
}
Run Code Online (Sandbox Code Playgroud)
我在我的 composer.json 中使用以下版本:
"laravel/framework": "5.6.*",
"jenssegers/mongodb": "3.4.*",
"phpunit/phpunit": "~7.0",
Run Code Online (Sandbox Code Playgroud)
服务器上使用了以下版本:
我使用安装在供应商目录中的 phpunit 调用测试:
vendor/phpunit/phpunit/phpunit
Run Code Online (Sandbox Code Playgroud) 我发现我无法更改.env文件中的内容,并让Laravel在下次运行时选择它。例如我改变了
APP_ENV=production
Run Code Online (Sandbox Code Playgroud)
至
APP_ENV=local
Run Code Online (Sandbox Code Playgroud)
跑步时
artisan migrate
Run Code Online (Sandbox Code Playgroud)
我仍然被问到是否确定要在生产环境中运行迁移。有没有一种解决方法,而不必每次更新.env文件时都清除缓存?
我是Cartalyst Sentinel的新手和ACL的概念.我设法创建了一个用户,执行激活,登录和注销.
我想把我的学习提升到一个新的水平.我想在这个laravel应用程序上有两种类型的用户.1是管理员另一个是订阅者.我假设我的帐户创建方法应该默认为用户创建一个订阅者.
public function postCreate() {
/* Validation */
$validation = Validator::make(Input::all(), [
'email' => 'required|email|max:50|unique:users',
'username' => 'required|min:3|max:20|unique:users',
'password' => 'required|min:6',
'password_repeat' => 'required|same:password',
]);
if ($validation->fails()) {
return Redirect('login')->withErrors($validation)->withInput();
} else {
$credentials = Input::all();
$user = Sentinel::register($credentials);
$activation = Activation::create($user);
$activation_code = $activation->code;
if ($user) {
Mail::send('emails.auth.activate', ['link' => URL::route('account-activate', [$user->id, $activation_code]), 'username' => $user->username], function($message) use ($user) {
$message->to($user->email, $user->username)->subject('Activate your account');
});
return Redirect::route('home')->with('global', 'Thank you for registering! We have sent you an email …Run Code Online (Sandbox Code Playgroud) laravel ×4
php ×3
laravel-4 ×2
acl ×1
apple-watch ×1
clockkit ×1
docker ×1
email ×1
file-upload ×1
go ×1
import ×1
ios ×1
javascript ×1
laravel-4.2 ×1
laravel-5.6 ×1
mongodb ×1
node.js ×1
phpunit ×1
sentinel ×1
swiftmailer ×1
swiftui ×1
xcode ×1