$rules = [ 'password'=>'required|between:6,20|confirmed', ]; $message = [ 'password.required'=>'新密碼不能為空!', 'password.between'=>'新密碼必須在6-20位之間!', 'password.confirmed'=>'新密碼和確認密碼不一致!',//password_confirmation ]; //驗證規則 $validator = Validator::make($input,$rules,$message); //返回boolean if(!$validator->passes()) { return back()->withErrors($validator); }
laravel中使用ajax
function changeOrder(obj,cate_id){ var cate_order = $(obj).val(); $.post( "{{url('admin/category/changeOrderData')}}", {'_token':'{{csrf_token()}}','cate_id':cate_id,'cate_order':cate_order}, function(data){ if(data.status > 0){ layer.msg(data.msg,{icon:6}); }eles{ layer.msg(data.msg,{icon:5}); } } ); }
laravel中的表單添加必須要包含
{{csrf_field()}}
laravel中的put方法提交
<input type="hidden" name="_method" value="put" > {{csrf_field()}}
//過濾出表單中_token 和_method 字段
Input::except('_token','_method')
uploadify的使用
<tr>
<th><i class="require">*</i>縮略圖:</th>
<td>
<input type="text" size="40px" name="art_thumb">
<button id="file_upload"></button>
</td>
</tr>
<tr>
<th></th>
<td>
<img src="" alt="" id="art_thumb" style="max-height: 200px;max-width: 500px;" />
</td>
</tr>
js代碼
<script>
var ue = UE.getEditor('editor',{initialFrameWith:'80%',initialFrameHeight:450});
<?php $timestamp = time();?>
$(function() {
$('#file_upload').uploadify({
'buttonText':'圖片上傳',
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'_token' : "{{csrf_token()}}"
},
'swf' : "{{asset('resources/org/uploadify/uploadify.swf')}}",
'uploader' : "{{url('admin/upload')}}",
'onUploadSuccess':function (file,data,response) {
$("input[name='art_thumb']").val(data);
$("#art_thumb").attr('src','/'+data);
}
});
});
</script>
laravel上傳圖片
public function upload() { $file = Input::file('Filedata'); if($file->isValid()){ $extension = $file->getClientOriginalExtension(); $newName = date('YmdHis').mt_rand(100,999).".".$extension; $path = $file->move(base_path()."/uploads",$newName); $filepath = 'uploads/'.$newName; return $filepath; /*//檢驗上傳的文件是否有效 $clientName = $file->getClientOriginalName();//獲取文件名稱 $tmpName = $file->getFileName(); //緩存在tmp文件中的文件名 例如 php9732.tmp 這種類型的 $realPath = $file->getRealPath(); //這個表示的是緩存在tmp文件夾下的文件絕對路徑。 $entension = $file->getClientOriginalExtension(); //上傳文件的后綴 $mimeType = $file->getMimeType(); //得到的結果是imgage/jpeg $path = $file->move('storage/uploads'); //如果這樣寫的話,默認會放在我們 public/storage/uploads/php9372.tmp //如果我們希望將放置在app的uploads目錄下 並且需要改名的話 $path = $file->move(app_path().'/uploads'.$newName); //這里app_path()就是app文件夾所在的路徑。$newName 可以是通過某種算法獲得的文件名稱 //比如 $newName = md5(date('YmdHis').$clientName).".".$extension;*/ } }

