Ich erstellte eine Route zu einer einfachen Kontaktseite. Ich verwende einen Controller, um die Daten in der Datenbank zu speichern und sie auf derselben Seite anzuzeigen. Wenn ich das Formular abschicke, bekomme ich eine leere Seite, aber ich möchte, dass der Benutzer auf dem Kontakt bleibt. Ich habe versucht, die Indexansicht zu übergeben, aber dann bekomme ich Fehler.Laravel 5.2 Controller-Index gibt leere Seite
Die Dateien sind
route.php
Route::get('contact', '[email protected]');
Route::post('contact', '[email protected]');
ContactController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Contact;
class ContactController extends Controller
{
public function index() {
$contacts = Contact::orderBy('created_at', 'asc')->get();
return view('/contact', [ 'contacts' => $contacts ]);
}
public function create(Request $request) {
$name = $request->input('name');
$contact = new Contact;
$contact->name = $name;
$contact->save();
#return view('/contact');
}
}
contact.php
contact.blade.php
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">Contact page</div>
<div class="panel-body">
{!! Form::open(array('url' => 'contact')) !!}
{!! Form::label('name', 'Name') !!}
{!! Form::text('name'); !!}
{!! Form::submit('Submit'); !!}
{!! Form::close() !!}
@if (count($contacts) > 0)
@foreach ($contacts as $contact)
{{ $contact->name }}
@endforeach
@endif
</div>
</div>
</div>
</div>
</div>
@endsection
Einfach 'view ('contact' .....)' den Schrägstrich entfernen! –
Ich schrieb gerade die gleiche Antwort wie Ismail RBOH sagt Remember to acces ist mit Punkt anstelle von Schrägstrich und ohne blade.php Notation –
Das löst das Problem nicht. – Xenioz