我为我的商家信息创建了一个编辑页面,出于某种原因,当我转到listings/view/{id}/edit
时,我被重定向到listings/view/{id}
这是ListingsController.php中的getEdit()方法
public function getEdit($id)
{
$listings = Listing::find($id);
$this->layout->content = View::make('listings/edit')
->with('listings', $listings);
}
这是views/listings/edit.blade.php
<h1>Editing {{ $listings->id }}</h1>
<!-- if there are creation errors, they will show here -->
{{ HTML::ul($errors->all()) }}
{{ Form::model($listings, array('route' => array('listings/edit', $listings->id), 'method' => 'PUT')) }}
<div class="form-group">
{{ Form::label('status', 'Status') }}
{{ Form::email('status', null, array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('listingfor', 'For') }}
{{ Form::select('listingfor', array(
'' => 'Listing For',
'For Sale' => 'For Sale',
'For Rent' => 'For Rent',
'Sale-Rent' => 'Sale - Rent'
),'',
array('class' => 'form-control'
)) }}
</div>
{{ Form::submit('Edit', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
这是routes.php
Route::controller('users', 'UsersController');
Route::controller('listings', 'ListingsController');
Route::post('listings/add', array('uses' => 'ListingsController@setAdd'));
Route::get('contacts', function()
{
return View::make('listings.add');
});
Route::get('listings/edit/{id}', array('uses' => 'ListingsController@getEdit'));
Route::get('listings/view/{id}', array('uses' => 'ListingsController@getView'));
Route::get('add', array('uses' => 'ListingsController@getAdd'));
Route::controller('/', 'HomeController');
来自artisan routes
+--------+-----------------------------------------------------------------+------+----------------------------------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------+-----------------------------------------------------------------+------+----------------------------------+----------------+---------------+
| | GET|HEAD users/register/{one?}/{two?}/{three?}/{four?}/{five?} | | UsersController@getRegister | | |
| | GET|HEAD users/login/{one?}/{two?}/{three?}/{four?}/{five?} | | UsersController@getLogin | | |
| | GET|HEAD users/logout/{one?}/{two?}/{three?}/{four?}/{five?} | | UsersController@getLogout | | |
| | GET|HEAD users/dashboard/{one?}/{two?}/{three?}/{four?}/{five?} | | UsersController@getDashboard | | |
| | POST users/create/{one?}/{two?}/{three?}/{four?}/{five?} | | UsersController@postCreate | | |
| | POST users/signin/{one?}/{two?}/{three?}/{four?}/{five?} | | UsersController@postSignin | | |
| | GET|HEAD|POST|PUT|PATCH|DELETE users/{_missing} | | UsersController@missingMethod | | |
| | GET|HEAD listings/main/{one?}/{two?}/{three?}/{four?}/{five?} | | ListingsController@getMain | | |
| | GET|HEAD listings/view/{one?}/{two?}/{three?}/{four?}/{five?} | | ListingsController@getView | | |
| | GET|HEAD listings/add/{one?}/{two?}/{three?}/{four?}/{five?} | | ListingsController@getAdd | | |
| | GET|HEAD listings/edit/{one?}/{two?}/{three?}/{four?}/{five?} | | ListingsController@getEdit | | |
| | POST listings/edit/{one?}/{two?}/{three?}/{four?}/{five?} | | ListingsController@postEdit | | |
| | POST listings/add/{one?}/{two?}/{three?}/{four?}/{five?} | | ListingsController@postAdd | | |
| | GET|HEAD|POST|PUT|PATCH|DELETE listings/{_missing} | | ListingsController@missingMethod | | |
| | POST listings/add | | ListingsController@setAdd | | |
| | GET|HEAD contacts | | Closure | | |
| | GET|HEAD listings/edit/{id} | | ListingsController@getEdit | | |
| | GET|HEAD listings/view/{id} | | ListingsController@getView | | |
| | GET|HEAD add | | ListingsController@getAdd | | |
| | GET|HEAD|POST|PUT|PATCH|DELETE {_missing} | | HomeController@missingMethod | | |
+--------+-----------------------------------------------------------------+------+----------------------------------+----------------+---------------+
答案 0 :(得分:0)
您正在手动调用列表/编辑路线,但您应该使用内置函数,因此:
{{ Form::model($listings, array('route' => array('listings/edit', $listings->id)...
应该是这样的:
{{ Form::model($listings, array('action' => array('ListingsController@edit', $listings->id)...
这样,Laravel知道你想要什么。
答案 1 :(得分:0)
默认情况下你已经拥有它:
GET|HEAD listings/view/{one?}/{two?}/{three?}/{four?}/{five?}
所以删除这两个:
Route::get('listings/edit/{id}', array('uses' => 'ListingsController@getEdit'));
Route::get('listings/view/{id}', array('uses' => 'ListingsController@getView'));