我遇到了一个需要更改需要验证的数据的实例,即当没有提交slug时,从标题创建一个然后验证它是唯一的.
请求有一个方法replace(),它应该替换请求中的输入数据,但它似乎不起作用.任何人都可以对此发光吗?这就是我所拥有的:
<?php namespace Purposemedia\Pages\Http\Requests;
use Dashboard\Http\Requests\Request;
use Illuminate\Auth\Guard;
class PageRequest extends Request {
/**
* [authorize description]
* @return {[type]} [description]
*/
public function authorize( Guard $auth) {
return true;
}
/**
* [rules description]
* @return {[type]} [description]
*/
public function rules() {
// Get all data from request
$data = $this->request->all();
if( $data['slug'] === '' ) {
// if the slug is blank, create one from title data
$data['slug'] = str_slug( $data['title'], '-' );
// …Run Code Online (Sandbox Code Playgroud) request laravel laravel-5 laravel-validation laravel-request
今天我发现我正在工作的项目存在性能问题。我使用 Laravel 框架,因此大多数查询不是手动生成的。
问题:
SELECT count(*) FROM table LEFT JOIN a ON table.a_id= a.id LEFT JOIN b ON table.b_id = b.id LEFT JOIN c ON table.c_id = c.id
Run Code Online (Sandbox Code Playgroud)
其中table执行了大约 100k 条记录,0,7s而
SELECT count(*) FROM table
Run Code Online (Sandbox Code Playgroud)
执行0,01s
所以性能损失是巨大的。问题是 - 是否可以在查询中添加任何内容以使查询执行得更快(告诉 MySQL 在没有 WHERE 条件时忽略 LEFT JOINS),第二个问题 - 为什么 MySQL 在这种情况下使用联接joins都是LEFT而没有在哪里?
这里的问题是我向查询添加了许多条件,因此有时会使用许多 WHERE(最多 20-30 个条件),并且对于某些条件必须使用连接。
目前我无法检查索引(它们很可能会导致问题),但我仍然惊讶于 MySQL 在这种情况下不会忽略连接。
作为一种解决方法,在这种情况下,当没有使用条件时,或者对于大约 10-15 个不需要连接的条件,我不会使用左连接进行计数,但对于其他情况,我应该map为需要的连接创建。
AS @Gordon Linoff 在答案中提到连接不会创建任何额外的行,如果没有连接的查询生成 10 行,如果使用这些连接,将返回完全相同的行。
我正在Laravel 5中编写代码来定期备份MySQL数据库.到目前为止我的代码看起来像这样:
$filename = 'database_backup_'.date('G_a_m_d_y').'.sql';
$destination = storage_path() . '/backups/';
$database = \Config::get('database.connections.mysql.database');
$username = \Config::get('database.connections.mysql.username');
$password = \Config::get('database.connections.mysql.password');
$sql = "mysqldump $database --password=$password --user=$username --single-transaction >$destination" . $filename;
$result = exec($sql, $output); // TODO: check $result
// Copy database dump to S3
$disk = \Storage::disk('s3');
// ????????????????????????????????
// What goes here?
// ????????????????????????????????
Run Code Online (Sandbox Code Playgroud)
我在网上看到的解决方案建议我做一些类似的事情:
$disk->put('my/bucket/' . $filename, file_get_contents($destination . $filename));
Run Code Online (Sandbox Code Playgroud)
但是,对于大文件,使用file_get_contents()不浪费吗?还有更好的解决方案吗?
假设我有一个模型Foo,我正在改变一个属性getter,就像这样:
class Foo extends Model
{
protected $table = 'foo';
public function getSomeBarAttribute($value)
{
return some_function($value);
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法访问属性的原始值,预变异?
嗨,我正在构建一个Laravel 5项目,该项目将部署在wordpress应用程序内的服务器上的子文件夹中(我不知道为什么,但客户端是客户端),然后我需要为应用程序中的所有路由添加前缀前缀如"/ es",现在的问题是与Auth相关的路由.在我的路线定义中,我有以下几行:
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
Run Code Online (Sandbox Code Playgroud)
我的问题是,有没有办法为这些路由添加前缀,而不必为从处理它们的特征中提取的auth控制器放置所有路由定义?
提前致谢.
我无法发送带有用户地址的电子邮件作为FROM和回复
在FormRequest中:
public function persist()
{
$reservation = Resa::create(
$this->only(['nom', 'email', 'phone', 'formule', 'date_arr', 'date_ret', 'nb_adu', 'nb_enf', 'lemessage'])
);
Mail::to('contact@cotiga.fr')
->from($reservation->email, $reservation->nom)
->replyTo($reservation->email, $reservation->nom)
->send(new Reservation($reservation));
}
Run Code Online (Sandbox Code Playgroud)
我有错误:
FatalThrowableError in ReservationForm.php line 48:
Call to undefined method Illuminate\Mail\PendingMail::from()
Run Code Online (Sandbox Code Playgroud)
我尝试了充分的可能性,但我无法改变字段FROM和REPLYTO你能帮助我吗?谢谢
我们假设我有以下主题:
abcdef ghidef
Run Code Online (Sandbox Code Playgroud)
我希望匹配以def结尾的字结尾,而不是abc(在这种情况下,它将是ghidef).我怎么能匹配呢?
我用的时候:
(?<!abc)def
Run Code Online (Sandbox Code Playgroud)
我得到了第二名,def但我没有ghi来到这里.
我正在创建一个Reply模型,然后尝试返回具有所有者关系的对象。这是返回空对象的代码:
//file: Thread.php
//this returns an empty object !!??
public function addReply($reply)
{
$new_reply = $this->replies()->create($reply);
return $new_reply->with('owner');
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我将with()方法换成load()方法以加载所有者关系,则可以得到预期的结果。那就是返回的回复对象及其相关的所有者关系:
//this works
{
$new_reply = $this->replies()->create($reply);
return $new_reply->load('owner');
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么。寻找澄清。
谢谢,耶
我正在尝试在注册步骤的第2步自动登录用户.成功插入db后,我正在Auth::loginUsingId($user_id)使用ajax自动登录用户.我总是CSRF在每个步骤上提交令牌.
现在问题是在成功登录CSRF令牌生成后,Auth::user()在步骤3中变为空白
登录前后CSRF也不同.
我正在尝试验证输入字段,但是当我使用验证规则时,它会抛出一个:The GET method is not supported for this route. Supported methods: POST.错误。
这是我的控制器
public function delivery(Request $request)
{
$request->validate([
'code' =>'required|numeric|size:4'
]);
return view('frontEnd.orderInfo');
}
Run Code Online (Sandbox Code Playgroud)
这是路线:
Route::post('/delivery','orderController@delivery');
Run Code Online (Sandbox Code Playgroud)
这是视图
<form id="loginform" action="{{url('delivery')}}" class="form-horizontal" method="post" role="form" enctype="multipart/form-data">
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
{{method_field('POST')}}
{{ csrf_field() }}
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-phone"></i></span>
<input type="password" class="form-control" name="code" value="" placeholder="enter code.">
</div>
<div style="margin-top:10px" class="form-group">
<!-- Button --> …Run Code Online (Sandbox Code Playgroud)