我已经在Laravel中创建了一个表单,用于将注册数据提交到数据库。在其他有效的视图中,我与其他形式所做的相同。检查了拼写错误,但是当我按下“提交”按钮时,什么也没发生。
“ registrations / create.blade.php”中的表单HTML
<form method="POST" action="{{route('registrations.store')}}"></form>
<div class="container">
<p>Prašome užpildyti visus laukus.</p>
<hr>
@csrf
<label for="vardas"><b>Vardas</b></label>
<input type="text" placeholder="Įveskite savo vardą" name="vardas" required>
<label for="pavarde"><b>Pavardė</b></label>
<input type="text" placeholder="Įveskite savo pavardę" name="pavarde" required>
<label for="el_pastas"><b>El. paštas</b></label>
<input type="text" placeholder="Įveskite savo el. paštą" name="el_pastas" required>
<label for="tel_nr"><b>Telefono nr.</b></label>
<input type="text" placeholder="Įveskite savo telefono nr." name="tel_nr" required>
<b>Pasirinkite norimą gitaros mokytoją</b><br><br>
<input type="radio" name="mokytojas_id" value="1"> Petras Petrauskas<br>
<input type="radio" name="mokytojas_id" value="2"> Andrius Rimiškis<br>
<input type="radio" name="mokytojas_id" value="3"> Virgis Stakėnas<br>
<hr>
<button type="submit" class="registerbtn"><b>Registruotis</b></button>
</div>
</form>
'routes.web.php'
Route::get('/', 'PagesController@index');
Route::get('/contacts', 'PagesController@contacts');
Route::get('/form', 'PagesController@form');
Route::get('/guitarists', 'PagesController@guitarists');
Route::get('/news', 'PagesController@news');
Route::resource('questions', 'QuestionsController');
Route::resource('registrations', 'RegistrationsController');
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/admin', 'AdminController@dashboard');
Route::resource('guitarists', 'MokytojaiController');
型号
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Registration extends Model
{
protected $fillable = ['vardas', 'pavarde', 'el_pastas', 'tel_nr', 'mokytojas_id'];
}
控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Registration;
class RegistrationsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//$questions = DB::select('SELECT * FROM questions');
//$questions = Question::orderBy('id','desc')->take(1)->get();
//$questions = Question::orderBy('id','desc')->get();
$registrations = Registration::orderBy('id','desc')->paginate(10);
return view ('registrations.index')->with('registrations', $registrations);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('registrations.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'vardas' => 'required',
'pavarde' => 'required',
'el_pastas' => 'required',
'tel_nr' => 'required',
'mokytojas_id' => 'required'
]);
$post = $request->all();
Registration::create($post);
return redirect('/registrations/create')->with('status', 'Registracija atlikta!');
}
答案 0 :(得分:4)
您的表单标签立即关闭。
<form method="POST" action="{{route('registrations.store')}}"></form>
您在此处发布时是这种类型,还是最有可能是问题所在。 Button没有执行任何操作,因为它不在form标记内。