حصلت على الخطأ التالي أثناء قيامي بعملية حذف بيانات على laravel 5.1، ورسالة الخطأ كالآتي:
MethodNotAllowedHttpException in RouteCollection.php line 219:
in RouteCollection.php line 219
at RouteCollection->methodNotAllowed(array('DELETE')) in RouteCollection.php line 206
Route::delete('cats/{cat}/delete', function(Furbook\Cat $cat){
$cat->delete();
return redirect('cats')->withSuccess('Cat has been deleted');
});
عرض لبقية المسارات بالتطبيق:
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return redirect('cats');
});
Route::get('cats', function () {
$cats = Furbook\Cat::All();
return view('cats.index')->with('cats',$cats);
});
Route::get('cats/create', function(){
return view('cats.create');
});
Route::post('cats', function(){
$cat = Furbook\Cat::create(Input::all());
return redirect('cats/'.$cat->id)->withSuccess('Cat has been created');
});
Route::get('cats/{id}', function ($id) {
$cat = Furbook\Cat::findOrNew($id);
return view('cats.show')->with('cat',$cat);
});
Route::get('cats/{cat}', function(Furbook\Cat $cat){
return view('cats.show')->with('cat',$cat);
});
Route::delete('cats/{cat}/delete', function(Furbook\Cat $cat){
$cat->delete();
return redirect('cats')->withSuccess('Cat has been deleted');
});
Route::get('about', function () {
return view('about')->with('number_of_cats',9000);
});
Route::get('cats/breeds/{name}', function ($name) {
$breed = Furbook\Breed::with('cats')
->whereName($name)
->first();
$cats = null;
if(isset($breed))
$cats=$breed->cats;
return view('cats.index')
->with('breed',$breed)
->with('cats',$cats);
});
وبطريقة أخرى عند كتابة الأمر php artisan route:list :
السؤال
Simoh
حصلت على الخطأ التالي أثناء قيامي بعملية حذف بيانات على laravel 5.1، ورسالة الخطأ كالآتي:
MethodNotAllowedHttpException in RouteCollection.php line 219: in RouteCollection.php line 219 at RouteCollection->methodNotAllowed(array('DELETE')) in RouteCollection.php line 206رابط الحذف على التطبيق هو:
<a href="{{ url('cats/'.$cat->id.'/delete') }}"> <span class="glyphicon glyphicon-trash"></span> Delete </a>مسار الحذف كان بهذا الشكل:
Route::delete('cats/{cat}/delete', function(Furbook\Cat $cat){ $cat->delete(); return redirect('cats')->withSuccess('Cat has been deleted'); });عرض لبقية المسارات بالتطبيق:
<?php /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', function () { return redirect('cats'); }); Route::get('cats', function () { $cats = Furbook\Cat::All(); return view('cats.index')->with('cats',$cats); }); Route::get('cats/create', function(){ return view('cats.create'); }); Route::post('cats', function(){ $cat = Furbook\Cat::create(Input::all()); return redirect('cats/'.$cat->id)->withSuccess('Cat has been created'); }); Route::get('cats/{id}', function ($id) { $cat = Furbook\Cat::findOrNew($id); return view('cats.show')->with('cat',$cat); }); Route::get('cats/{cat}', function(Furbook\Cat $cat){ return view('cats.show')->with('cat',$cat); }); Route::delete('cats/{cat}/delete', function(Furbook\Cat $cat){ $cat->delete(); return redirect('cats')->withSuccess('Cat has been deleted'); }); Route::get('about', function () { return view('about')->with('number_of_cats',9000); }); Route::get('cats/breeds/{name}', function ($name) { $breed = Furbook\Breed::with('cats') ->whereName($name) ->first(); $cats = null; if(isset($breed)) $cats=$breed->cats; return view('cats.index') ->with('breed',$breed) ->with('cats',$cats); });وبطريقة أخرى عند كتابة الأمر php artisan route:list :
+--------+----------+--------------------+------+---------+------------+ | Domain | Method | URI | Name | Action | Middleware | +--------+----------+--------------------+------+---------+------------+ | | GET|HEAD | / | | Closure | | | | GET|HEAD | about | | Closure | | | | POST | cats | | Closure | | | | GET|HEAD | cats | | Closure | | | | GET|HEAD | cats/breeds/{name} | | Closure | | | | GET|HEAD | cats/create | | Closure | | | | GET|HEAD | cats/{cat} | | Closure | | | | DELETE | cats/{cat}/delete | | Closure | | | | GET|HEAD | cats/{id} | | Closure | | +--------+----------+--------------------+------+---------+------------+ما هو الخطأ الذي ارتكبته وكيف أتمكّن من حلّه؟
1 جواب على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.