【发布时间】:2019-03-27 03:33:53
【问题描述】:
每次我想在表单中使用 Action() 时都会收到此错误
Action App\Http\Controllers\RentBikeController@store not defined. (View: C:\xampp\htdocs\BikeRental\resources\views\Pages\bike.blade.php)
我的控制器代码是:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class RentBikeController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
echo 'chuj';
}
/**
* 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($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
查看代码
{!! Form::open(['action' => 'RentBikeController@store']) !!}
<div class="form-group">
{{Form::label('title', 'Title')}}
{{Form::text('title', '', ['class' => 'form-conrol', 'placeholder'=> 'Title'])}}
</div>
<div class="form-group">
{{Form::label('body', 'Body')}}
{{Form::textarea('body', '', ['class' => 'form-conrol', 'placeholder'=> 'text'])}}
</div>
{{Form::submit('submit', ['class' => 'btn btn-primary'])}}
{!! Form::close() !!}
我知道我可以使用 Route::post('/bike/1','BikeController@store') 这样的东西,但我真的不想要。
我也尝试使用此解决方案Adding form action in html in laravel,但随后又出现了另一个错误
【问题讨论】:
-
其实是我抄的时候搞错了。代码编辑
-
我相信你需要将它添加到你的
web.php路由文件中,以便 Laravel “看到”它。