Created
May 4, 2018 16:14
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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