2

I have a system whereby you can go and create different documents. From a select list, I could select for instance Project Brief, and this would display the Project Brief form to me whereby I could add data to complete a project brief. I could also select other documents from the select, and the form displayed to me would be appropriate for the chosen document.

One issue I had was I had created a new database table for each document type, and also a new Model, Controller etc. I knew this was going to get out of hand if I created many types of documents, so I decided to change things a bit. My new database design is like so Database design

So I am making a generic documents table which I can use to make different documents. I was hoping now to have a generic Document Model, so I do not need a new Model for each type of Document. The project I am facing is this. From within my projects page, I have a drop down menu where you can select the type of document you want to create. One example is this

{!! link_to_route('projects.projectBrief.create', 'Project Brief', array($project->id)) !!}

The route for the above is as follows

Route::model('projects.projectBrief', 'Document');
Route::resource('projects.projectBrief', 'Docs\DocumentController', ['except' => ['index', 'show']]);

So it is using the project briefs view, but also using the generic Document Controller. Now in my Document Controller, at the moment my create function is something like the following

public function create(Project $project)
{
    return View::make('projectBrief.create', compact('project'));
}

This is fine for this document, but because other Document types will use the same Controller, I need a way to separate things. How would I go about doing this? So if I chose Reporting Document from the select option, the above create method should return the view for the reportingDoc. How can I determine what view to return?

Thanks

1 Answer 1

1

There are any number of ways to do this, I would recommend adding documentType as a parameter in your link to the form.

{!! link_to_route('projects.projectBrief.create', 
    'Project Brief', 
    array('projectId' => $project->id, 'documentType' => 'projectBrief')) !!}

Note this will require making a change to your controller to pick up the named projectId and documentType parameters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.