vendredi 27 mai 2016

Redirecting to view files

just wanted to firstly note is that this works fine when I have the redirects within their own retrspective functions. Essentially, I create a Project. Within a Project I can make many types of Documents. Relationships are all set up appropiately.
So within a Project I have links to different documents which can be created. These are like

<li>{!! link_to_route('projects.document.create', 'Some Document',  array($project, 'someDocument')) !!}</li>

The route is like this

Route::get('projects/{projects}/document/{name}', array('as' => 'projects.document.create', 'uses' => 'DocumentController@create'));

And then in my DocumentController I do this

public function create(Project $project, $name)
{
    $this->redirectResult($project, $name);
}

The redirectResult function essentially checks to see if the selected document (in this case someDocument) has been created before (A project can have many documents, but only one of each type). If the document has never been created for the project, it shows the create view for that document. If it has been created before it shows the edit view. This is the function

public function redirectResult(Project $project, $name) {
    $selectedDoc = Document::where('project_id', '=', $project->id)
        ->where('name', '=', $name)
        ->first();

    if(!$selectedDoc) {
        return View::make($name.'.create', compact('project'));
    }
    else {
        return View::make($name . '.edit', compact('project', 'selectedDoc'));
    }
}

Now when I select a document, I end up on a blank page. The url is correct, no errors or anything, simply a blank page. The strange thing is when I do it the old way (which should act the same as the above) it works. The old way is exactly the same as above, but my create function is like this instead

public function create(Project $project, $name)
{
    $selectedDoc = Document::where('project_id', '=', $project->id)
        ->where('name', '=', $name)
        ->first();

    if(!$selectedDoc) {
        return View::make($name.'.create', compact('project'));
    }
    else {
        return View::make($name . '.edit', compact('project', 'selectedDoc'));
    }
}

So the only different is that the view making code is directly within the function, rather than calling a function that has this code. I wanted to put all this repeat code in its own function so I do not have to repeat it for every document controller function.

Is there any reason why my new way takes me to a blank page? Just to rule out the obvious, I do have the folders containing the view files set up correctly. So for the above example within the views folder I have a folder called someDocument and within it I have edit.blade.php.

Any information as to why this might be occuring appreciated.

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire