anibabbar
1 week ago
399
16
Laravel

404 error on form update

Posted 1 week ago by anibabbar

Once I submit form I receive 404 error. I couldn't figure out error !! Hope someone could help.

Controller :

public function update(Request $request, $id)
    {
        // return $request;

        $bank = Bankaccounts::find($id);

        // return $bank;
        $user = Auth::user()->id;

        if($bank->user_id !== $user) {
           return  redirect('bank');
         } else { 
        $bank->name = $request->name;
        $bank->account_no = $request->account_no;
        $bank->code = $request->code;
        $bank->credit_limit = $request->credit_limit;
        $bank->currency = $request->currency;
        $bank->user_id = $parent_id;
        $bank->emp_id = $user_id;

        $bank->save();

        $redirect = $_SERVER['HTTP_REFERER'];
   
        return redirect($redirect);
         }
    }

View :

@extends('layouts.dashboard')
@section('title', 'Update Bank')

@section('content')
<form action="/bank/{{$bank->id}}" method="POST">
@csrf
@method('put')
<div class="col-md-6">
<div class="card">
    <div class="card-header">
        <h4 class="card-title">Update Details</h4>
    </div>
    <div class="card-body">
  <div class="form-group row">
    <label for="name" class="col-4 col-form-label">Bank name</label> 
    <div class="col-8">
      <input id="name" name="name" type="text" class="form-control" value="{{$bank->name}}">
    </div>
  </div>
  <div class="form-group row">
    <label for="Account No" class="col-4 col-form-label">Account No</label> 
    <div class="col-8">
      <input id="Account No" name="account_no" type="text" class="form-control" aria-describedby="Account NoHelpBlock" value="{{$bank->account_no}}"> 
      <span id="account_noHelpBlock" class="form-text text-muted">optional</span>
    </div>
  </div>
  <div class="form-group row">
    <label for="code" class="col-4 col-form-label">Code</label> 
    <div class="col-8">
      <input id="code" name="code" type="text" class="form-control" aria-describedby="codeHelpBlock" value="{{$bank->code}}"> 
      <span id="codeHelpBlock" class="form-text text-muted">optional</span>
    </div>
  </div>
  <div class="form-group row">
    <label for="Credit Limit" class="col-4 col-form-label">Credit Limit</label> 
    <div class="col-8">
      <input id="credit_limit" name="credit_limit" type="text" class="form-control" aria-describedby="Credit LimitHelpBlock" value="{{$bank->credit_limit}}"> 
      <span id="credit_limitHelpBlock" class="form-text text-muted">optional</span>
    </div>
  </div>
  <div class="form-group row">
    <label for="currency" class="col-4 col-form-label">Currency</label> 
    <div class="col-8">
      <input id="currency" name="currency" type="text" class="form-control" value="{{$bank->currency}}">
    </div>
  </div> 


    </div>
    <!-- card-body -->
        <div class="border-top">
            <div class="card-body">
<input type="submit" value="Update Bank" class="btn btn-primary">              </div>
        </div>
       
  
</div>

</div>
<!-- col-md-6 -->
</form>
@endsection

Route:

 Route::put('/bank/{$id}', '[email protected]');

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