我在Laravel应用程序中创建了一个服务提供程序SettingsServiceProvider.这会缓存数据库中的设置表.
$settings = $cache->remember('settings', 60, function() use ($settings)
{
return $settings->pluck('value', 'name')->all();
});
config()->set('settings', $settings);
Run Code Online (Sandbox Code Playgroud)
settings 表:
我能够像这样回显表中的值:
{{ config('settings.sitename') }} //returns Awesome Images
Run Code Online (Sandbox Code Playgroud)
这适用于任何刀片文件或控制器 App\Http\Controllers
问题:
我试图回应这样的价值App\config\mail.php:
'driver' => config('settings.maildriver'),
'host' => config('settings.mailhost'),
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误:
Missing argument 1 for Illuminate\Support\Manager::createDriver()
Run Code Online (Sandbox Code Playgroud)
更新:
我创建了一个新的服务提供程序MailServiceProvider来覆盖Mail.php中的设置,如下所示:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Config;
class MailServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,用户从日期选择器中选择日期,然后日期将以对应用户区域设置的格式显示在输入中.
提交表单时,我想验证相应的日期,但验证者不知道提交日期的日期格式.
我的问题是我是否应该在将日期传递给验证器之前将日期变为Ymd,还是有一种方法可以告诉Validator正确的格式进行验证?
for循环应该循环10次。当我刚打印了$fname,$lname并且$email
我得到了10个数据(工作正常)
但是我需要将这些值存储在关联数组中。
$assocDataArray = array();
foreach ($data as $key => $value) {
foreach ($value['emails'] as $lead) {
$fname = $lead['first_name'];
$lname = $lead['last_name'];
$email = $lead['value'];
//put objects in array
$assocDataArray += [ "First Name" => $fname ];
$assocDataArray += [ "Last Name" => $lname ];
$assocDataArray += [ "Email" => $email ];
}
}
var_dump($assocDataArray);
Run Code Online (Sandbox Code Playgroud)
var_dump 只给我一个数组[预期10]
我设置了一个包含3个页面的应用程序,分别是“首页”,“爬行动物”和“地图”。
我的问题来自“爬行动物和地图”页面。在爬行动物页面上,我显示了一个物种列表,每个物种都有一个范围国家列表和一个链接“查看此处的地图”。当用户单击某个国家/地区时,我希望显示突出显示所选国家/地区的地图页面(我尚未实现该功能,因此,现在,我只希望将该国家/地区传递到地图页面)。
当用户单击某个物种的“在此处查看地图”时,我希望显示地图页面,并突出显示该物种的所有范围国家。现在,我可以在react-router的Route中传递爬行动物和国家/地区的道具,但是当我尝试直接在Reptlie.js文件中的链接中传递道具时,出现错误警告:reptile标记上的未知道具。
从元素中删除此道具。有人可以帮我弄清楚如何将props直接传递到组件中的链接吗?另外,您将如何生成动态URL?例如,map / species1或map / country1?
我认为我的问题出在Reptiles.js中。react-router的版本是3.0.2
下面是我的结构:
下面是我的代码:router.js:
const routes = (
<Router history={browserHistory}>
<Route component={App}>
<Route path="/" component={Home}/>
<Route path="reptiles" name="reptiles" component={Reptiles}/>
<Route path="map" name="map" component={Map} country="Taiwan" reptile="Beardy"/>
</Route>
</Router>
);
export default routes;
Run Code Online (Sandbox Code Playgroud)
App.js:
class App extends Component {
render() {
return (
<div className="container">
<header>
<span className="icn-logo"><i className="material-icons">code</i></span>
<ul className="main-nav">
<li><NavLink to="/">Home</NavLink></li>
<li><NavLink to="/reptiles">Reptiles</NavLink></li>
<li><NavLink to="/map">Map</NavLink></li>
</ul>
</header>
{this.props.children}
</div>
);
}
}
export default App;
Run Code Online (Sandbox Code Playgroud)
Reptiles.js:
const Reptiles = () …Run Code Online (Sandbox Code Playgroud) 我创造了一个可邮寄的 php artisan make:mail SendInEmail
class SendInEmail extends Mailable
{
use Queueable, SerializesModels;
public $email;
public $sub;
public $emailcontent;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($email, $sub, $emailcontent)
{
$this->email = $email;
$this->sub = $sub;
$this->emailcontent = $emailcontent;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject($sub)->view('emails.sendemail');
}
}
Run Code Online (Sandbox Code Playgroud)
在构建函数中,我传递的$sub变量来自控制器,但它给了我一个错误:
Undefined variable: sub
我用这个时:
return $this->subject('Some subject')->view('emails.sendemail');
Run Code Online (Sandbox Code Playgroud)
它工作正常.
PS我做了一些研究,发现我需要use函数传递主题变量(一些匿名函数魔法)(不知道如何用mailables做)
因此,我在Axios上使用了这种发布方法,如果我提交了该方法,它会说
未捕获(承诺)错误:XMLHttpRequest.handleError(xhr.js:87)处createError(createError.js:16)出现网络错误
如果我使用这种方法:
axios.post('http://localhost:5000/users', ({userid: this.state.userid})
Run Code Online (Sandbox Code Playgroud)
有用。但是,如果我在axios帖子中添加2个或更多arg,它将再次出错:
axios.post('http://localhost:5000/users', ({userid: this.state.userid}, {fullname: this.state.fullname} ))
Run Code Online (Sandbox Code Playgroud)
这是我的完整代码。如您所见,我尝试使用不同的代码组合,并且只有在我仅传递1个arg的情况下,它才有效。
import React from 'react';
import axios from 'axios';
// import { Form } from 'antd';
// import { List, Card, Form } from 'antd';
export default class FormUser extends React.Component {
// constructor(props) {
// super(props)
// this.state = {
state = {
userid: '',
fullname: '',
usergroup:'',
emailid: '',
mobile: '',
title: '',
};
handleChange = event => {
this.setState({ userid: event.target.value });
this.setState({ fullname: …Run Code Online (Sandbox Code Playgroud) 在我的UserController我有一个函数
public function userFollow($id)
{
$authuser = Auth::user();
$authuser->follow($id);
//mail goes to the followiee ($id)
$followiee = User::where('id', $id)->first();
$to = $followiee->email;
Mail::to($to)->send(new MyMail);
return redirect()->back()->with('message', 'Following User');
}
Run Code Online (Sandbox Code Playgroud)
我还创建了一个邮件 MyMail
class MyMail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.welcome');
}
}
Run Code Online (Sandbox Code Playgroud)
在我的欢迎电子邮件中,我需要访问一些变量,例如$to在 …
这是我的代码:
setInterval(function() {
$.ajax({
type: "GET",
url: "someurl",
dataType: "json",
success: function(data) {
//Some code
}
});
}, 25 * 1000);
Run Code Online (Sandbox Code Playgroud)
上面的代码每25秒调用一次ajax方法.但是我第一次需要它在10秒内调用它,然后每25秒调用一次.
所以我跟着这个
并将我的代码更改为以下内容:
setTimeout(function() {
setInterval(function() {
$.ajax({
type: "GET",
url: "someurl",
dataType: "json",
success: function(data) {
//Some code
}
});
}, 25 * 1000);
}, 10 * 1000);
Run Code Online (Sandbox Code Playgroud)
但它似乎仍然没有奏效.
php ×5
laravel ×4
javascript ×3
laravel-5 ×2
reactjs ×2
arrays ×1
axios ×1
for-loop ×1
jquery ×1
laravel-5.4 ×1
mysql ×1
post ×1
react-router ×1
rest ×1