该路由不支持GET方法。支持的方法:PUT

时间:2019-06-02 00:27:05

标签: php post laravel-5 eloquent get

我想将值存储到数据库并重定向到新页面,但是发现此错误。我多次更改了代码,但显示了相同的错误。 我一直在寻找此错误。如果有任何避免这种错误的方法,请提供给我。我尝试了很多可能的操作,但错误是相同的。任何更改都无济于事。

Route.php

            Route::get('/create',   ['as'=>'creates','uses'=>'CAsController@create2']);
            Route::put('/postca', 'CAsController@storing');

CAsController         

    namespace App\Http\Controllers;
    use App\CAModel;
    use Illuminate\Http\Request;

   class CAsController extends Controller
    {
    public function create2(){
    return view('chartered.create');
}
public function storing(Request $request)
{
    // Handle File Upload
    if($request->hasFile('profile')){
        // Get filename with the extension
        $filenameWithExt = $request->file('profile')->getClientOriginalName();
        // Get just filename
        $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
        // Get just ext
        $extension = $request->file('profile')->getClientOriginalExtension();
        // Filename to store
        $fileNameToStore= $filename.'_'.time().'.'.$extension;
        // Upload Image
        $path = $request->file('profile')->storeAs('public/profile', $fileNameToStore);
    } else {
        $fileNameToStore = 'noimage.jpg';
    }


    // Handle File Upload
    if($request->hasFile('certificate')){
        // Get filename with the extension
        $filenameWithExt1 = $request->file('certificate')->getClientOriginalName();
        // Get just filename
        $filename1 = pathinfo($filenameWithExt1, PATHINFO_FILENAME);
        // Get just ext
        $extension1 = $request->file('certificate')->getClientOriginalExtension();
        // Filename to store
        $fileNameToStore1= $filename1.'_'.time().'.'.$extension1;
        // Upload Image
        $path1 = $request->file('certificate')->storeAs('public/certificate', $fileNameToStore1);
    } else {
        $fileNameToStore1 = 'noimage.jpg';
    }

    $ca = new CAModel;
    $ca->fname = $request->input('fname');
    $ca->lastname = $request->input('lastname');
    $ca->username = $request->input('username');
    $ca->city = $request->input('city');
    $ca->state = $request->input('state');
    $ca->zip = $request->input('zip');
    $ca->phone = $request->input('phone');
    $ca->email = $request->input('email');
    $ca->gstno = $request->input('gstno');
    $ca->website = $request->input('website');
    $ca->services = $request->input('services');
    $ca->profile = $fileNameToStore;
    $ca->certificate = $fileNameToStore1;  
    $ca->save();
    return redirect('/postca');
}

}

          <form action="/postca" method="POST">
        @method('PUT')
      @csrf
        <div class="row">
          <div class="col-sm-4">
            <div class="form-group">
              <input type="text" name="fname" id="fname" placeholder="First Name" class="form-control" required>
            </div>
          </div>
          <div class="col-sm-4">
              <div class="form-group">
                <input type="text" name="lastname" id="lastname" placeholder="Last Name" class="form-control" required>
              </div>
          </div>
          <div class="col-sm-4">
              <div class="form-group">
                <input type="text" name="username" id="username" placeholder="UserName" class="form-control" required>
              </div>
          </div>
        </div>  
        <div class="row">
            <div class="col-sm-4">
              <label for="city">City</label>
              <input type="text" class="form-control" id="city" name="city" placeholder="City" required> 
            </div>
            <div class="col-sm-4">
              <label for="state">State</label>
              <input type="text" class="form-control" name="state" id="state" placeholder="State" required> 
            </div>
            <div class="col-sm-4">
              <label for="zip">Zip</label>
              <input type="text" class="form-control" id="zip" name="zip" placeholder="Zip" required> 
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                    <label for="phone">Phone</label>
                    <input type="text" class="form-control" name="phone" id="phone" placeholder="Phone" required>
            </div>
            <div class="col-sm-6">
                    <label for="email">Email</label>
                    <input type="text" class="form-control" name="email" id="email" placeholder="Email" required>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6 col-md-4 col-sm-4">
                    <label for="gstno">GST No</label>
                    <input type="text" class="form-control" id="gstno" name="gstno" placeholder="GST number" required>    
            </div>
            <div class="col-sm-6 col-md-4 col-sm-4">
                    <label for="website">Website</label>
                    <input type="text" class="form-control" id="website" name="website" placeholder="GST number" required>
            </div>
        </div>
        <div class="form-group">
            <label for="services">Select the Services you provide</label>
            <select multiple class="form-control" name="services" id="services" multiple>
              <option>Propertiership</option>
              <option>One Person Company</option>
              <option>Limited Liability Partnership</option>
              <option>Private Limited Company</option>
              <option>Public Limited Company</option>
            </select>
          </div> 
          <div class="row">
              <div class="col-sm-6">
              <div class="form-group">
                  <div class="custom-file">
                          <input type="file" class="custom-file-input" id="profile" name="profile" required>
                          <label class="custom-file-label" for="profile">Profile Photo</label>
                  </div>
              </div>
              </div>
          <div class="col-sm-6">
          <div class="form-group">
              <div class="custom-file">
                      <input type="file" class="custom-file-input" id="certificate" name="certificate" required>
                      <label class="custom-file-label" for="certificate">Company Incorporation Certifcate</label>
              </div>
          </div>
          <div class="form-group">
              <input class="btn btn-primary" type="submit" value="Go!">
          </div>
          </form>

1 个答案:

答案 0 :(得分:0)

在您的控制器中,您返回return redirect('/postca');。该错误来自以下事实:重定向始终是GET个请求,而您似乎没有GET的{​​{1}}路由。

将重定向更改为/postca路由或添加GET路由。