Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message error

Published 5 months ago by deladels

so i am trying to build a crude system. the index method works or more like all the get methods/verbs work. but anytime i try to submit a form or edit an entry i get the above error.

namespace App\Http\Controllers;

use App\AdminBus;

use Illuminate\Http\Request;

class AdminBusController extends Controller
{

    //function/action to get all buses in the db
    public function index(AdminBus $addbus)
    {
        $addbus = AdminBus::all();

        return view('admin.addbus.index', compact('addbus'));
    }


    //function/action to create a new bus
    public function create()
    {
        return view('admin.addbus.create');
    }

    public function store(Request $request)
    {
       $this->validate( request(), [

            'busRegNo'  => 'required',
            'busModel'  => 'required',
            'capacity'  => 'required'

        ]);

        AdminBus::create([

        'reg_number'  => request('busRegNo'),
        'model'       => request('busModel'),
        'capacity'    => request('capacity')

    ]);
            Session::flash('message', 'Successfully created nerd!');
            return Redirect::to('bus'); 
    }

    
    public function show($adminBus)
    {
        $adminBus = AdminBus::find($adminBus);

        return view('admin.addbus.show', compact('adminBus'));
    }

  
    public function edit($adminBus)
    {
        $adminBus = AdminBus::find($adminBus);

        return view('admin.addbus.edit', compact('adminBus'));
    }


    public function update(Request $request, AdminBus $adminBus)
    {
        $adminBus = AdminBus::find($adminBus);

       $this->validate( request(), [

            'busRegNo'  => 'required',
            'busModel'  => 'required',
            'capacity'  => 'required'

        ]);
       
        $adminBus->reg_number = $request->get('reg_number');
        $adminBus->model      = $request->get('model');
        $adminBus->capacity   = $request->get('capacity');
        $adminBus->save();

            Session::flash('message', 'Successfully created nerd!');
            return Redirect::to('bus');
    }

web.php file

Route::resource('bus', 'AdminBusController');

any help?

bestmomo

Hello,

Are you sure you use good verbs in your forms ?

deladels

@bestmomo yes i do.

edit.blade.php

<form class="col 12" method="POST" style="padding-top: 20px;">
    {{ csrf_field() }}
    {{ method_field('PUT') }}
    
    <div class="container">
        <div class="row">
            <div class="input-field col s6">
                <input class="validate" type="text" name="busRegNo" value="{{ $adminBus->reg_number }}"></input>
                <label><b>Registration Number</b></label>
            </div>
            <div class="input-field col s6">
                <input class="validate" type="text" name="busModel" value="{{ $adminBus->model }}"></input>
                <label><b>Model</b></label>
            </div>
        </div>
        <div class="row">
            <div class="input-field col s6">
                <input class="validate" name="capacity" type="number" value="{{ $adminBus->capacity }}"></input>
                <label for=""><b>Capcity</b></label>
            </div>
            <div class="input-field col s6">
                
            </div>
        </div>
        <div class="row">
            <div class="col offset-m2 m4">
                  <button class=" red darken-1 btn waves-effect waves-light" type="submit">SUBMIT<i class="material-icons right">send</i>
                  </button>
            </div>
         </div>
    </div>
        </div>
    </div>
</form>

create.blade.php


<form class="col 12" method="POST" action="">
    {{ csrf_field() }}
    <div class="container">
        <h5 class="center-align">Add A New Bus</h5>
        <div class="row">
            <div class="input-field col s6">
                <input class="validate" type="text" name="busRegNo"></input>
                <label><b>Registration Number</b></label>
            </div>
            <div class="input-field col s6">
                <input class="validate" type="text" name="busModel"></input>
                <label><b>Model</b></label>
            </div>
        </div>
        <div class="row">
            <div class="input-field col s6">
                <input class="validate" name="capacity" type="number"></input>
                <label for=""><b>Capacity</b></label>
            </div>
            <div class="input-field col s6">
                
            </div>
        </div>
        <div class="row">
            <div class="col offset-m2 m4">
                  <button class=" red darken-1 btn waves-effect waves-light" type="submit">SUBMIT<i class="material-icons right">send</i>
                  </button>
            </div>
         </div>
    </div>
        </div>
    </div>
</form>

``

Please sign in or create an account to participate in this conversation.