Tuesday, September 29, 2020
Laravel request validation extend
<?php namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class PostRequest extends FormRequest
{
public function authorize()
{
// we can check more things
return true;
}
public function rules()
{
switch ($this->method()) {
case 'GET':
case 'DELETE': {
return [
'id'=>'required|exists:posts,id'
];
}
case 'POST': {
return [
'title'=> 'required|min:10',
'description' => 'required'
];
}
case 'PUT':
case 'PATCH': {
return [
'id'=>'required|exists:posts,id'
'title'=> 'required|min:10',
'description' => 'required'
];
}
default:
break;
}
}
}
Laravel ajax query param
<input type="hidden" name="_token" value="{{csrf_token()}}">
or use only CSRF blade directive
@csrf
$(function(){
$('#form').submit(function(e){
e.preventDefault();
var _url = $(this).attr('action'),
_type = 'POST',
_data = $(this).serialize();
$.ajax({
url: _url,
type: _type,
data: _data,
success: function (data) {
// do something after success
}
});
})
});
Larave .htaccess sucrity code
#disable directory browsing
Options -Indexes
#PROTECT ENV FILE
<Files .env>
order allow,deny
Deny from all
</Files>
#PROTECT ENV FILE
<Files .htaccess>
order allow,deny
Deny from all
</Files>
Subscribe to:
Posts (Atom)
-
Composer is a major part of the Laravel MVC Framework, but it also exists without Laravel. In fact you could use it in any project. This a...
-
How to Answer Technical Questions Like a Pro Answering technical interview questions is all about showing off your problem-solving skills an...
-
Vuetify is a popular UI framework for Vue apps. In this article, we’ll look at how to work with the Vuetify framework. Color Picker Inputs W...