2016-10-20 32 views
0

我有這種形式,有一個textarea。我應該輸入消息並顯示內容。但是,我得到這個錯誤MethodNotAllowedHttpException in RouteCollection.php line 218:我想不出一種解決辦法。我已經嘗試過,但得到相同的線路錯誤。如何在Laravel methodNotAllowed(array('POST'))中解決這個錯誤?

下面是我的代碼 我的刀片:

<form class="form-horizontal" role="form" method="post" action="sendbulk"> 
{{ csrf_field() }} 
<div class="form-group"> 
<label for="message" class="col-sm-1 control-label">Message</label> 
<div class="col-sm-6"> 
<textarea class="form-control" rows="4" name="message" required placeholder="Message"></textarea> 
</div> 
</div> 
<div class="form-group"> 
<div class="col-sm-6 col-sm-offset-1"> 
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary pull-right"> 

<a href="/sendsms" class="btn btn-default pull-left"> 
<i class="fa fa-arrow-left" aria-hidden="true"></i> Cancel </a> 
</div> 
</div> 
</form> 

我的路線:

Route::get('/', function() { 
return view('welcome'); 
}); 

Auth::routes(); 

Route::get('/home', '[email protected]'); 
Route::get('/receipts', '[email protected]'); 
Route::post('sendreceipt/{id}','[email protected]'); 
Route::get('/sendsms', '[email protected]'); 
Route::post('/sendbulk', '[email protected]'); 
Route::post('/selectContacts','[email protected]'); 
Route::get('/registerUsers', '[email protected]'); 
Route::get('/companyprofile', '[email protected]'); 
Route::post('/companyProfile', '[email protected]'); 
Route::get('/view-most-valuable-customers', '[email protected]'); 

Route::get('users', ['as' => 'UsersController', 'uses' => '[email protected]']); 
Route::get('users-data', ['as' => 'UsersControllerUsersData', 'uses' => '[email protected]']); 

Route::get('/settings', '[email protected]'); 
Route::get('/admin', '[email protected]'); 

Route::get('payments', ['as' => 'HomeController', 'uses' => '[email protected]']); 
Route::get('payments-data', ['as' => 'HomeControllerPaymentsData', 'uses' => '[email protected]']); 

Route::get('sms', ['as' => 'SmsController', 'uses' => '[email protected]']); 
Route::get('Sms-data', ['as' => 'SmsControllerSmsData', 'uses' => '[email protected]']); 

Route::get('logs', ['as' => 'LogsController', 'uses' => '[email protected]']); 
Route::get('Logs-data', ['as' => 'LogsControllerLogsData', 'uses' => '[email protected]']); 

我的控制器:

<?php 
namespace App\Http\Controllers; 
use Illuminate\Http\Request; 
use Validator,Auth, DB; 
use App\Http\Requests; 
use Yajra\Datatables\Facades\Datatables; 
class SmsController extends Controller 
{ 
/** 
* Create a new controller instance. 
* 
* @return void 
*/ 
public function __construct() 
{ 
$this->middleware('auth'); 
} 

public function sendsms(Request $request){ 

$message=$request->messsage; 

$validator = Validator::make($request->all(), [ 
'messsage' => 'required|max:160',]); 

if ($validator->fails()) { 
return redirect('/selectContacts') 
     ->withErrors($validator) 
     ->withInput();} 

echo $message;  
} 
} 

會有人親切地指向我,爲什麼我得到這個錯誤? 錯誤:

MethodNotAllowedHttpException in RouteCollection.php line 218: 

    in RouteCollection.php line 218 
    at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 205 
    at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 158 
    at RouteCollection->match(object(Request)) in Router.php line 755 
    at Router->findRoute(object(Request)) in Router.php line 610 
    at Router->dispatchToRoute(object(Request)) in Router.php line 596 
    at Router->dispatch(object(Request)) in Kernel.php line 267 
    at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53 
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46 
+0

Hi @MarcBrillault。不,一切都在默認位置。資源/視圖... – bmm

+0

似乎表單動作是相對的,所以除非當前URI是''''',否則URL將會出錯。你可以嘗試在表單動作中添加斜槓嗎? –

+0

Hello @SteveChamaillard我確實嘗試過,但仍然收到相同的錯誤。我不知道什麼是錯的! – bmm

回答

0

您是否可以更新您的路線以刪除第一個斜線?

Route::post('sendbulk', '[email protected]'); 
+0

我曾試過,但似乎不工作呢! – bmm