using same form request for create and update

Submitted by hardevine - 5 years ago

using same form request for create and update

//MessageRequest.php
public function rules()
{
if( $this->is('message/create') ) {
    return $this->createRules();
} elseif ( $this->is('message/update/*') ) {
    return $this->updateRules();
}
}

public function createRules()
{
return [
    'email' => 'required|email|max:50',
    'category' => 'required',
    'subject' => 'required|max:100',
    'message' => 'required|max:500'
]
}

public function updateRules()
{
return [
    'email' => 'required|email|max:50',
    'subject' => 'required|max:100',
    'message' => 'required|max:500'
]
}