Xnoar
158
11
Laravel

form does nothing laravel 5.8

Posted 1 week ago by Xnoar

I am developing a system of quotes with roles and permissions, the method of creating is not working, however it is a strange error because when doing the tests I insert the first record, but it did not do it with the following ones, it does not show error at the time of giving send only refreshes the page and does not insert the data.

When trying to do dd does not show anything, nor does it generate any error just refreshes the page.

controller

 public function create()
{
    
 $products = product::select('id','name')->orderBy('id')->get();
 $coateds = coated::select('id','name')->orderBy('id')->get();
 $materials = material::select('id','name')->orderBy('id')->get();
 $clients = Client::select('id','name')->orderBy('id')->get();
    return view('admin.quotations.create',compact('products','coateds','materials','clients'));
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
    $this->validate($request,[
        'description'=>'required',
        'price'=>'required',
        'tax'=>'required',
        'subtotal'=>'required',
        'total'=>'required',
        'quantity'=>'required',
        'client_id'=>'required',
        'product_id'=>'required',
        'material_id'=>'required',
        'coated_id'=>'required',

      ]);

     $requestValues = $request->all();
           $quotation = quotation::create([
              'description'=>$requestValues['description'],
              'price'=>$requestValues['price'],
              'tax'=>$requestValues['tax'],
              'subtotal'=>$requestValues['subtotal'],
              'total'=>$requestValues['total'],
              'quantity'=>$requestValues['quantity'],
              'client_id'=>$requestValues['client_id'],
              'product_id'=>$requestValues['product_id'],
              'material_id'=>$requestValues['material_id'],
              'coated_id'=>$requestValues['coated_id'],
              

            ]);
        
    return redirect()-> route('admin.quotations.edit', $quotation->id)->with('info','Cotizacion guardada con exito');
}

Model

 class quotation extends Model

{

protected $table = 'quotations';

protected $fillable = [
   'description', 'price', 'tax', 'sub_total', 'total','quantity', 'client_id','product_id','coated_id','material_id'
];

public function client()

{ return $this->belongsTo('App\Client'); } }

Routes

Route::post('admin/quotations/store','[email protected]')->name('quotations.store')
    ->middleware('can:quotations.create');

    Route::get('admin/quotations','[email protected]')->name('quotations.index')
    ->middleware('can:quotations.index');

    Route::get('admin/quotations/create','[email protected]')->name('quotations.create')
    ->middleware('can:quotations.create');

    Route::put('admin/quotations/{quotation}','[email protected]')->name('quotations.update')
    ->middleware('can:quotations.edit');

    Route::get('admin/quotations/show/{quotation}','[email protected]')->name('quotations.show')
    ->middleware('can:quotations.show');

    Route::delete('admin/quotations/{quotation}','[email protected]')->name('quotations.destroy')
    ->middleware('can:quotations.destroy');

    Route::get('admin/quotations/{quotation}','[email protected]')->name('quotations.edit')
    ->middleware('can:quotations.edit');  

Views

@extends('admin.template')

@section('content')

Cotizaciones [Generar nueva Cotizacion]

{{ __('Registro de Cotizaciones') }} @if(count($errors)>0) @include('admin.partials.error') @endif {{csrf_field()}}
      <div class="form-group row">
          <label for="description" class="col-md-4 col-form-label text-md-right">{{ __('Descripcion') }}</label>

          <div class="col-md-6">
              <input  type="text" class="form-control" name="description" required>
          </div>
      </div>

      <div class="form-group row">
          <label for="client_id" class="col-md-4 col-form-label text-md-right">{{ __('Cliente') }}</label>

          <select name="client_id">

            @foreach ($clients as $client)
                <option value="{{$client->id}}">
                  {{$client->name}}

                </option>

            @endforeach
          </select>

      </div>

      <div class="form-group row">
        <label for="product_id" class="col-md-4 col-form-label text-md-right">{{ __('Producto') }}</label>

        <select name="product_id">

          @foreach ($products as $product)
              <option value="{{$product->id}}">
                {{$product->name}}

              </option>

          @endforeach
        </select>

    </div>

    <div class="form-group row">
        <label for="material_id" class="col-md-4 col-form-label text-md-right">{{ __('Material') }}</label>

        <select name="material_id">

          @foreach ($materials as $material)
              <option value="{{$material->id}}">
                {{$material->name}}

              </option>

          @endforeach
        </select>

    </div>

    <div class="form-group row">
        <label for="coated_id" class="col-md-4 col-form-label text-md-right">{{ __('Acabado') }}</label>

        <select name="coated_id">

          @foreach ($coateds as $coated)
              <option value="{{$coated->id}}">
                {{$coated->name}}

              </option>

          @endforeach
        </select>

    </div>
    <div class="form-group row">
      <label for="price" class="col-md-4 col-form-label text-md-right">{{ __('Precio') }}</label>

      <div class="col-md-6">
          <input  type="text" class="form-control price" name="price" onchange="multiplicar();" required>
      </div>
  </div>

    <div class="form-group row">
      <label for="quantity" class="col-md-4 col-form-label text-md-right">{{ __('Cantidad') }}</label>

      <div class="col-md-6">
          <input  type="text" class="form-control quantity" name="quantity" onchange="multiplicar();" required>
      </div>
  </div>

  <div class="form-group row">
    <label for="sub_total" class="col-md-4 col-form-label text-md-right">{{ __('Subtotal') }}</label>

    <div class="col-md-6">
        <input  type="text" class="form-control subtotal" name="sub_total" required>
    </div>
</div>

    <div class="form-group row">
        <label for="tax" class="col-md-4 col-form-label text-md-right">{{ __('Impuesto') }}</label>

        <div class="col-md-6">
            <input  type="text" class="form-control tax" name="tax" onchange="multiplicar();" required>
        </div>
    </div>

    <div class="form-group row">
      <label for="total" class="col-md-4 col-form-label text-md-right">{{ __('Total') }}</label>

      <div class="col-md-6">
          <input  type="text" class="form-control total" name="total" required>
      </div>
  </div>


      <button type="submit" class="btn btn-info">Agregar Articulo</button>
    </form>

          </div>
      </div>
  </div>
function multiplicar (){ input1 = document.querySelector(".quantity").value; input2 = document.querySelector(".price").value; input3 = document.querySelector(".tax").value; subtotal = parseInt(input1)*parseInt(input2); impuesto = parseInt(subtotal)*parseInt(input3)/100; document.querySelector(".subtotal").value = subtotal; document.querySelector(".total").value = subtotal+impuesto;

}

@endsection

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