Hi @JeffreyWay, The form seems to still be doing something odd with the timezones. I just posted this and it's 57 min old. Which is weird. Seems like it should be correct or some function of 60 min old.
Is there a way to make a form request from another request
This may be a silly solution and there are others I could already make however I have this route set:
// This won't work unless you add some functionality to the root controller
// but this ins't the question. It's based on some tweets from spatie.be
// with some adamwathan comment ideas thrown in there.
// just putting this note in, incase any one tries this and breaks their "web.php"
Route::post('account/topic/{topic_slug}/type/{question_type}/' , TopicQuestionController::at('store'))->name('topic.question.store');
Route::get('account/topic/{topic_slug}/type/{question_type}/create' , TopicQuestionController::at('create'))->name('topic.question.create');
This store lets me respond to all question types, and depending on the "question_type", I would like to make a new form request out of the request data.
- simple solution is to just change question type into a hard coded path for example:
Route::post('account/topic/{topic_slug}/type/question-a/' , TopicQuestionAController::at('store'))->name('topic.question.a.store');
Route::post('account/topic/{topic_slug}/type/question-b/' , TopicQuestionBController::at('store'))->name('topic.question.b.store');
//etc ...
But this is a hobby project where I want to push the edge of my knowledge so ...
I have this store method:
public function store(Request $request, $topic_slug, $question_type)
{
if($question_type == 'questionA'){
$this->storeQuestionA($request, $topic_slug);
}
}
public function storeQuestionA(QuestionAForm $form, $topic_slug )
{
dd($form);
}
Now clearly this won't work I'm trying to pass a request object into another differing object even though it extends request. However if I asked for a QuestionAForm directly in the controller store method from the route, laravel would have auto-wired it for me in the original store method.
Anyone know where laravel does that or how I could implement that middle step of converting the request to another form request object?
Love Taylor Otwell, his video on the laracon.net is so jam packed full of goodies. It gives all the hints about where to look to solve this, but basically you can create one form request from another, since all form requests extend Illuminate\Http\Request, they have a static method called "createFrom"
So you can code something like this to pass on a more specific version of your request:
$questionAForm = QuestionAForm::createFrom($request);
$this-> storeQuestionA($questionAForm, $topic_slug);
It won't automatically validate the form anymore, I can't figure out why the ValidatesWhenResolved service provider is not kicking in, but I'm clearly making the class AFTER it's gone through the middleware pipeline.
as of right now you can validate it by running this in your storeQuestionA function
public function storeQuestionA(QuestionAForm $form, $topic_slug){
$this->validate($form, $form->rules()); // now validating old school
}
Please or to participate in this conversation.