lundi 28 novembre 2016

How to pass data to view returned by the route redirected to (Laravel)

The following is my situation.

I have two models with controllers containing CRUD methods.

  • Document.
  • File.

While creating a file, an already document is to be specified (selected) to which the created file will be attached to.

In the store method of my documentController after storing the newly created document I want to redirect to files/create route with the id of newly created document, so that files can be created without having to choose a document.

What I have so far

DocumentController

 $input = $request->all();
 $document = $this->documentRepository->create($input);
 return redirect(route('files.create'),array('documentID' => $document->id));

file/create.blade.php

@if( isset($documentID) )
<input type="text" name="document_id" value="" hidden="true">

@else
<div class="form-group col-sm-6">

    {!! Form::label('file_type', 'Document ID:') !!}

    <select name="document_id" class="form-control">
        @foreach( $documents as $document)
            <option value="">-</option>
        @endforeach
    </select>
</div>
@endif

How can i achive this.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire