【发布时间】:2019-06-23 18:49:11
【问题描述】:
最近我一直在努力使用 laravel 将数据插入数据库。一切都很顺利。但知道我遇到了错误:“使用未定义的常量联系人 - 假定为'联系人'”。我不知道如何解决这个问题。
我已经在 Laracast 网站上查看是否可以找到有关如何解决此问题的解释,但我找不到,因为答案不是我想要的。我也看过 StackOverflow。但是(再次)没有答案可以帮助我解决这个问题。我也问过我的一个同学,他也解决不了。
我的控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\contacts;
class ContactsController extends Controller
{
/*Haal alle data op uit de contact tabel return een view file*/
public function index($contact = contacts){
$Contact = contacts::all();
return view('contact',compact('contacts'));
}
/*Return een view file*/
public function create(){
return view('contacts');
}
public function storeContact(){
/*Maakt nieuwe variabele, wanneer er op de knop wordt geklikt worden er 2 waardes opgehaald.*/
$contacts = new contacts();
$contacts->name = request('voornaam');
$contacts->description = request('bericht');
$contacts->save();
return redirect('/contacts');
}
}
我的看法:
@extends ('Layout')
@section('title')
Contact
@endsection
@section('content')
<br>
<h2>Contact</h2>
<p>Voor verdere informatie (die u niet op onze website kunt vinden) kunt u ons bereiken op onze email of telefoonnummer:</p>
<p>Email: Cronensteynfake@gmail.com</p>
<p>telefoonnummer: 06-11122234</p>
<br>
U kunt ook ons contactformulier invullen.
<br><br>
<h2>Cronenstyn Contactformulier</h2>
<form action="" method="post">
@csrf
<div class="form-group">
<label for="exampleInputPassword1">Voornaam</label>
<input type="text" class="form-control" id="Vnaam" placeholder="Voornaam">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Achternaam</label>
<input type="text" class="form-control" id="Anaam" placeholder="Achternaam">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email</label>
<input type="email" class="form-control" id="Email" aria-describedby="emailHelp" placeholder="Uw email">
<small id="emailHelp" class="form-text text-muted">Wij delen uw email met niemand</small>
</div>
<label for="exampleInputEmail1">Bericht</label>
<div class="form-group shadow-textarea">
<textarea class="form-control z-depth-1" id="bericht" rows="3" placeholder="Uw bericht"></textarea>
</div>
<button onclick="Message()" type="submit" class="btn btn-primary">Verzenden</button>
<script>
function Message() {
alert("Uw bericht is met succes verstuurd.");
}
</script>
</form>
@endsection
我的路线:
<?php
Route::get('/', function () {
return view('welcome');
});
Route::GET('/home',('CronensteynController@home'));
Route::GET('/nieuws',('CronensteynController@nieuws'));
Route::GET('/galerij',('CronensteynController@gallerij'));
Route::GET('/activiteit',('CronensteynController@activiteit'));
Route::GET('/contact',('CronensteynController@contact'));
Route::GET('/about',('CronensteynController@about'));
Route::get('/beheer', 'PageController@beheer');
Route::get('/create_beheer', 'PageController@Create_beheer');
Route::get('/update_beheer', 'PageController@Update_beheer');
Route::get('/delete_beheer', 'PageController@delete_beheer');
Route::post('/create_beheer', 'CreateBeheerController@store');
Route::post('/contact', 'contactsController@index');
希望我已经为您提供了有关该问题的足够信息和代码。
您好,
Parsa_237
【问题讨论】:
-
$contact = contacts应该是$contact = "contacts" -
谢谢!错误消失了,但现在我有一个说找不到类 App/contacts?
-
你在混用'contacts'和'Contacts',看看model name是'contacts'还是'Contacts'。
-
嗨,谢谢你的回答 Sujeet。我已经更改了模型名称,现在它又可以使用了。您想发布这个答案而不是评论,而是一个答案,以便我可以说这个问题得到了回答?