0

I have replaced my entity with Blog to explain better.

I have the following route:

Route::get('/blog-category', 'BlogController@showBlogCategory')

which shows a form with a dropdown of different blog categories and some other input fields related to the category

The form POSTs to the following:

Route::post('/blog-details', 'BlogController@showBlogDetails')

Here I validate the request the form and return back if there is an invalid blog category or if it is missing

This method is called showBlogDetails because the category and the other fields are passed on to the next view return view('blog-details', compact('blogCategoryData'))

In this view there is a form to fill in the rest of the blog details.

Both the blogCategoryData (each data has a hidden input field) and the blog details are POSTed to the following route:

Route::post('/blog-store', 'BlogController@store')

This is also validated using a Request but if it fails it tries to go back, which it can't do as only POST is allowed to get there.

I need the blog category fields before I can show the blog details and a Blog cannot be created without either stuff so I can't temporarily create one either.

This flow of selecting/filling in blog category fields and then entering details is a requirement so has to be done in that order, in 2 different pages.

So currently it is: GET -> POST (validate) -> POST (validate)

What is the best way around this or how would I make my current flow work?

H H
  • 2,065
  • 1
  • 24
  • 30
  • Why don't you move adding category to the separate page and then in the blog creation page you only need to select the category which is already checked and validated in the category creation page – ashok poudel Feb 26 '18 at 13:44
  • @ashokpoudel do you mean move everything in to one page? – H H Feb 26 '18 at 13:45
  • No I mean . create a page where you create the categories and in the second page where you create post create a dropdown where you can select category and fill the other field of the blog post – ashok poudel Feb 26 '18 at 13:48
  • @ashokpoudel i can do but i think that it will be an extra table for no reason, because it's not really a thing on it's own and it will always belong to a single `Blog` so it should really be in the `Blog` table – H H Feb 26 '18 at 14:21
  • No a category can have many post. Let us consider an example where the tourism is the category . Then you can have many post related to tourism . So you created a different table for the category and put foreign key of category in the blog table – ashok poudel Feb 26 '18 at 14:30

1 Answers1

1

one way is to use javascript and of course ajax to fetch blog data and show corresponding section. first the page only shows categories drop down box. after changing that to a correct category page makes an ajax request and fetches data. then replaces it in a hidden 'div' and shows it.

another way is to bring replace the categories box in the previous page.

Amin.Qarabaqi
  • 661
  • 7
  • 19