Skip to content

Instantly share code, notes, and snippets.

@raymond1988
Created May 4, 2018 16:14
Show Gist options
  • Save raymond1988/04a1e3fc8845691ef26244a7e81d1d20 to your computer and use it in GitHub Desktop.
Save raymond1988/04a1e3fc8845691ef26244a7e81d1d20 to your computer and use it in GitHub Desktop.
This code is for validating update requests in laravel. It's implemented using the laravel form request feature which can be implemented using php artisan:make request UpdateBlogPostRequest.
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateBlogPostRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() {
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules() {
//post received from update function parameter
$id = $this->post->id;
return [
'title' => "bail|required|max:255|unique:posts,title,$id",
'description' => 'required|max:255',
'content' => 'required',
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment