以下软删除代码对我来说很好:
$post = Post::find($post_id);
$post->delete();
Run Code Online (Sandbox Code Playgroud)
deleted_at字段已更新.但这给了我一个错误:
$post = Post::find($post_id);
$post->restore();
Run Code Online (Sandbox Code Playgroud)
这是错误:
exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to a member function restore() on a non-object'
Run Code Online (Sandbox Code Playgroud)
我很难过.到目前为止谷歌没有帮助.
我需要我的模型只从一个表中返回那些记录在另一个表中不存在的记录.我当时认为解决方案可能与查询范围有关,但文档仅涉及表面.所以我的SQL看起来像这样:
SELECT *
FROM A
WHERE NOT EXISTS (SELECT A_id FROM B
WHERE B.A_id = A.id)
Run Code Online (Sandbox Code Playgroud)
这是我的表格:
A
-------------
| id | name |
-------------
B
--------------------
| id | A_id | name |
--------------------
Run Code Online (Sandbox Code Playgroud)
可能没必要,但这里是我的模特.A型号:
class A extends Eloquent{
public function B(){
return $this->hasOne('B', 'A_id', 'id');
}
}
Run Code Online (Sandbox Code Playgroud)
B模型:
class B extends Eloquent{
public function A(){
return $this->belongsTo('B', 'A_id', 'id');
}
}
Run Code Online (Sandbox Code Playgroud) 有没有办法在每封电子邮件发送之前使用Laravel的"Event"类来运行一些代码?我也喜欢取消的能力Mail::send();.
当然,在发送电子邮件之前我可以这样做:
Event::fire('email.beforeSend');
Run Code Online (Sandbox Code Playgroud)
然后我可以这样听:
Event::listen('email.beforeSend', function()
{
//my code here
});
Run Code Online (Sandbox Code Playgroud)
这个问题是我必须记住Event::fire()我不想做的事情.在我的情况下,我正在反对取消订阅列表的电子邮件地址,以确保我不发送任何垃圾邮件.
我在我的应用程序中实现了Laravel的标准密码重置功能.除了我在我的收件箱中收到2封"重置密码"电子邮件外,它的效果很好.(附注可能没有任何意义:其中一封电子邮件没有主题,另一封电子邮件没有.)我认为我没有做任何与众不同的事情,所以我很难过.有任何想法吗?
public function getRemind(){
$view = View::make('password.remind');
$view->title = 'my title';
return $view;
}
Run Code Online (Sandbox Code Playgroud)
在remind.blade.php上形成
{{ Form::open(array('url'=>'do-reset')) }}
<fieldset>
<label for="email">Email Address</label>
{{ Form::email('email', $email, array('id'=>'email')) }}
<div id="button_wrap">
<input type="submit" id="submit" name="submit" value="Send Reset Email">
</div>
</fieldset>
@if(Session::has('status'))
<p>{{ Session::get('status') }}</p>
@endif
@if(Session::has('error'))
<p>{{ Session::get('error') }}</p>
@endif
{{ Form::close() }}
Run Code Online (Sandbox Code Playgroud)
do-reset的路由:
Route::post('do-reset', array('uses'=>'RemindersController@postRemind'));
Run Code Online (Sandbox Code Playgroud)
我没有在postRemind()方法中改变任何东西:
public function postRemind(){
Password::remind(Input::only('email'), function($message){
$message->subject('Click on the link below to reset your password.');
});
switch ($response = Password::remind( Input::only('email') ) ){
case Password::INVALID_USER:
return …Run Code Online (Sandbox Code Playgroud) 在Laravel 4中,我可以这样做以获取表前缀:
$prefix = DB::getTablePrefix();
Run Code Online (Sandbox Code Playgroud)
L5中的等价物是什么?
目前,我的 htaccess 文件将我所有子域的非 https 请求重定向到 https... 除了 www 请求。即http://subdomain.example.com被重定向到https://subdomain.example.com(这是正确的),但www.subdomain.example.com重定向到https://www.subdomain.example.com(不正确)。这是我的 .htaccess 代码:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Trying to redirect to https
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)