我正在L5.2中创建一个CRUD系统,并使用Bootstrap Modal来显示表单.我使用了BootForms和Laravel Bootstrap Modal Form来验证表单并在Modal中显示错误消息而不关闭它.
基本上我在同一页面上的模态中打开添加/编辑表单,表单验证在Modal内部完成,一旦一切正常,数据将被插入数据库并且模式关闭.之后页面刷新并显示更新的数据.
一切都很好,除非成功,我无法在我的页面上显示成功消息.
以下是我的代码:
AJAX
$.ajax({
type: "POST",
url: url,
data: data,
dataType: 'json',
cache: false,
contentType: contentType,
processData: false
// Response.
}).always(function(response, status) {
// Reset errors.
resetModalFormErrors();
// Check for errors.
if (response.status == 422) {
var errors = $.parseJSON(response.responseText);
// Iterate through errors object.
$.each(errors, function(field, message) {
console.error(field+': '+message);
var formGroup = $('[name='+field+']', form).closest('.form-group');
formGroup.addClass('has-error').append('<p class="help-block">'+message+'</p>');
});
// Reset submit.
if (submit.is('button')) {
submit.html(submitOriginal);
} else if (submit.is('input')) …Run Code Online (Sandbox Code Playgroud) 以下是我的代码:
模型:
class Slide extends \Eloquent {
// Add your validation rules here
public static $rules = [
'title' => 'required|between:3,100',
'image' => 'required',
'url' => 'url',
'active' => 'integer'
];
// Don't forget to fill this array
protected $fillable = ['title', 'image', 'url', 'active'];
}
Run Code Online (Sandbox Code Playgroud)
控制器更新方法:
public function update($id)
{
$slide = Slide::find($id);
$validator = Validator::make($data = Input::all(), Slide::$rules);
if ($validator->fails())
{
return Redirect::back()->withErrors($validator)->withInput();
}
$slide->update($data);
return Redirect::route('admin.slides.index')
->with('message', 'Slide has been updated.')
->with('message-type', 'alert-success');
}
Run Code Online (Sandbox Code Playgroud)
路线:
Route::group(array('prefix' => …Run Code Online (Sandbox Code Playgroud) 我在我的网站上有一个成员列表,并且他们的成员资格开始日期和有效日期作为时间戳存储在我的数据库中。现在我想给他们发送电子邮件
如何根据存储的到期日期确定是否还剩一个月/周/天?
该项目在Laravel 4.2中完成,我正在使用Carbon。
有任何想法吗?