2017-02-28 4 views
0

Ich versuche CRUD-Anwendung in Laravel 5.4 zu erstellen, aber und ich bin fertig mit erstellen und Anzeige Formular jetzt verbleibenden bearbeiten und löschen, aber das Bearbeitungsformular zeigt Informationen statt es bringt es Ein Create-Formular und erstellt einen neuen Datensatz anstelle von create. Jede Hilfe wäre appreciated.Below ist mein ControllerBearbeitungsformular zeigt keine Werte zum Bearbeiten in Laravel 5

<?php 

namespace App\Http\Controllers; 

use \App\Http\Requests\contactsrequest; 
use App\contacts; // contacts model included using "use" 


class contactscontroller extends Controller 
{ 
    /** 
    * Display a listing of the resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function index() 
    { 
     //Display Data 
     //find contact by contacts model 
     // use model contacts and include the use App\contacts model 
     // variable contact holds all values of contacts table 
     $contact=contacts::all(); // contavt 
     return view('contacts.index',['contacts'=>$contact]); 
    } 

    /** 
    * Show the form for creating a new resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function create() 
    { 
     // 
     return view('contacts.create'); 
    } 

    /** 
    * Store a newly created resource in storage. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return \Illuminate\Http\Response 
    */ 
    public function store(contactsrequest $request) 
    { 
     //contacts model 
     contacts::create($request->all()); 
     return redirect()->route('contacts.index')->with('message', 'Contacts has been added successfully'); 
    } 

    /** 
    * Display the specified resource. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function show($id) 
    { 
     // 
    } 

    /** 
    * Show the form for editing the specified resource. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function edit(contacts $contacts) 
    { 
     // 

     return view('contacts.edit', compact('contacts')); 
    } 

    /** 
    * Update the specified resource in storage. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function update(contactsrequest $request, contacts $contacts) 
    { 
     // 
     $contacts->update($request->all()); 
     return redirect()->route('contacts.index')->with('message', 'Contacts has been updated successfully'); 

    } 

    /** 
    * Remove the specified resource from storage. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function destroy($id) 
    { 
     // 
    } 
} 





The edit form is below 
<!-- Home page to Display contacts --> 
@extends('master') 

@section('content') 
<div class="container"> 
<div class="row"> 
    <div class="col-md-10 col-md-offset-1"> 
<div class="panel panel-primary"> 
    <div class="panel-heading"> 
    <h3 class="panel-title">Update Contacts</h3> 
    </div> 
    <div class="panel-body"> 

      <!-- $contacts is object --> 
      {{Form::model($contacts, array('route'=>['contacts.update', $contacts->id],'method'=>'POST'))}} 
    <!-- input name, value is null, the parameters e.g class, placeholder etc --> 
     <div class="form-group"> 
     {{Form:: label('Name','Enter name') }} 
     {{Form:: text('Name',null, ['class'=>'form-control','placeholder'=>'Enter Name']) }} 
     </div> 
     <div class="form-group"> 
     {{Form:: label('Phone','Mobile Number') }} 
     {{Form:: text('Phone',null, ['class'=>'form-control','placeholder'=>'Enter Mobile Number']) }} 
     </div> 
     <div class="form-group"> 
     {{Form:: label('Email','Email Address') }} 
     {{Form:: email('Email', null, ['class'=>'form-control','placeholder'=>'Enter Email Address']) }} 
     </div> 

     <div class="form-group"> 
      {{ Form::button('Update',['class'=>'btn btn-primary', 'type'=>'submit'])}} 
      | 
     <a href="{{route('contacts.index')}}" class="btn btn-warning btn-sm"> <i class="fa fa-plus-square fa-lg" aria-hidden="true" style="border: none;"></i>Back</a> 
      </div> 
     {{Form:: close() }} 

    </div> 
    </div> 

</div> 
</div> 
</div> 
@endsection 
+0

wo ist das Formular? –

+0

Ich habe den Bearbeitungsformular-Code enthalten ... Überprüfen Sie jetzt, ich habe bearbeitet –

Antwort

0

versuchen Sie dies in Ihrem Controller

0

Ihrer Sicht erwartet das Modell $ Kontakte aufgerufen werden, so ändern Sie Ihre bearbeiten() -Methode in der Steuerung, die folgenden sein:

public function edit($id) 
    { 
     $contact = Contacts::findOrFail($id); 
     return view('contacts.edit', ['contacts' => $contact]); 
    } 
+0

NotFoundHttpException in Handler.php Zeile 131: Keine Abfrageergebnisse für Modell [App \ Kontakte] [] –

+0

versuchen Sie eine funktionierende (bestehende) ID –

Verwandte Themen