Ich versuche, meine Pivot-Tabelle zu aktualisieren approve_document, wo es eine zusätzliche Spalte isApprove
mit ->withPivot
Methode hat.updateExistingPivot wird nicht funktionieren
Modell:
Dokument
class Document extends Model
{
public function sentToApprovers()
{
return $this->belongsToMany('App\Models\Approve', 'approve_document')->withPivot('isApprove');
}
}
Genehmigen
class Approve extends Model
{
public function createdpendingDocuments()
{
return $this->belongsToMany('App\Models\Document', 'approve_document')->withPivot('isApprove');
}
}
Dies ist, wo ich in meinem approve_document alle meine Aufzeichnungen erhalten.
Controller:
public function documentsSentForApproval()
{
$pendingDocumentLists = DB::table('approve_document')
->select('documents.title', 'documents.content', 'categories.category_type', 'users.username', 'approve_document.dateReceived', 'documents.id', 'approves.approver_id')
->join('documents', 'documents.id', '=', 'approve_document.document_id')
->join('categories', 'categories.id', '=', 'documents.category_id')
->join('approves', 'approves.id', '=', 'approve_document.approve_id')
->join('users', 'users.id', '=', 'approves.approver_id')
->where('approver_id', '=', Auth::id())
->orWhere('requestedBy', '=', Auth::id())
->get();
return view ('document.pending')
->with('pendingDocumentLists', $pendingDocumentLists);
}
Ausblick:
@foreach ($pendingDocumentLists as $list)
<tr class = "info">
<td>{{ $list->title }}</td>
<td>{{ strip_tags(substr($list->content, 0, 50)) }} {{ strlen($list->content) > 50 ? "..." : '' }}</td>
<td>{{ $list->category_type }}</td>
<td>{{ $list->username }}</td>
<td>{{ date('M, j, Y', strtotime($list->dateReceived)) }}</td>
<td>
@if (Auth::id() == $list->approver_id)
<a href = "{{ route ('document.pending', $list->id) }}">
<button type = "submit" class = "btn btn-success glyphicon glyphicon-thumbs-up"> Approve</button>
</a>
@endif
</td>
<td></td>
</tr>
@endforeach
Sie können hier sehen, ich habe eine Schaltfläche genehmigen, wenn ich brauche isApprove
auf true gesetzt, wenn die Schaltfläche geklickt wird. Sie sehen, dass ich beim Klicken auf die Schaltfläche die aktuelle ID des Dokuments erhalte.
Dieser Teil des Controllers, in dem es mir schwer fällt, meine Pivot-Tabelle zu aktualisieren. Es gibt mir einen Fehler MethodNotAllowedHttpException
. Irgendwelche Tipps oder Hilfe würden sehr geschätzt!
public function updateIsApprove($id)
{
$document = new Document();
foreach ($document as $update)
{
$approve = new Approve();
$document->sentToApprovers()->updateExistingPivot([$approve->id => ['isApprove' => '1']],false);
}
return redirect()->route('document.pending');
}
Routen:
Route::post('/documents/pending/approve/{id}',
[
'uses' => '\App\Http\Controllers\[email protected]',
'as' => 'document.pending',
]);
Ist dies optional? Ich habe bei Laravel Dokumentation nichts gefunden. – Francisunoxx
Es ist erforderlich. Sehen Sie sich mein Beispiel an: $ comany-> members() -> updateExistingPivot ($ member-> id, ['is_admin' => true]); – Vuer
Ich habe nichts falsches mit Ihrem Code gesehen, aber ich habe versucht, folgen, aber nichts passiert, es wird nicht in meine Pivot-Tabelle aktualisiert. – Francisunoxx