I have a problem while creating edit and create forms
I have a form that is used to create and edit when I call $data on the form so that it appears when editing the form.
But when I open the form to create new data the error $data is undefined appears.
This is my route
Route::resource('/tabungan/jadwal-autodebet', SavingAccountScheduleController::class);
This is the create and edit script in my controller
public function create()
{
$info['header'] = $this->title;
$info['description'] = 'Tambah';
$info['breadcrumb'] = null;
return view('banking::autodebet-schedule.form',$info);
}
public function edit($id)
{
$info['header'] = $this->title;
$info['description'] = 'Ubah';
$info['breadcrumb'] = null;
$data = TransactionSchedule::find($id);
$origin = clone $data;
$origin = $data->origin;
$destination = clone $data;
$destination = $data->destination;
$destinationType = '';
$saving = SavingAccount::class;
$loan = LoanAccount::class;
if($data->origin_type == $saving){
$destinationType = 'Tabungan';
}elseif($data->origin_type == $loan){
$destinationType = 'Pinjaman';
}
// dd($data,$origin,$destination);
return view('banking::autodebet-schedule.form',compact('data','origin','destination','destinationType'),$info);
}
and this is my autodebet.schedule.form script
<form id="formData" action="{{ isset($data) ? admin_url('cb/tabungan/jadwal-autodebet/'.$data->id) : admin_url('cb/tabungan/jadwal-autodebet/')}}" method="POST" autocomplete="off">
{{ csrf_field() }}
#if(isset($data))
{{method_field('PUT')}}
#endif
<div class="container d-flex justify-content-center">
<div class="col-12">
<div class="row">
<div class="col-2">
<label class="label-required" for="" >Produk Tujuan</label>
</div>
<div class="col-10">
<select name="destination_type" id="destination_type" class="select2 form-control destination_type">
<option value="{{ $data->origin_type }}">{{ $destinationType }}</option>
<option class="type_option" id="SavingAccount" value="Modules\Banking\Entities\SavingAccount">Tabungan</option>
<option class="type_option" id="LoanAccount" value="Modules\Banking\Entities\LoanAccount">Pinjaman</option>
</select>
</div>
</div>
<div class="row">
<div class="col-2">
<label class="label-required" for="">No Rekening Sumber</label>
</div>
<div class="col-10">
<select id="origin_code" class="select2 form-control origin_code">
<option value="{{ $origin->id }}">{{ $origin->saving_code }}-{{ $origin->customer->customer_name}}-{{ $destinationType }}</option>
</select>
</div>
</div>
<div class="row">
<div class="col-2">
<label class="label-required" for="" >Transaksi Rekening Anggota/Nasabah Lain</label>
</div>
<div class="col-10">
<input type="hidden" id="other_costumer_transaction" name="other_costumer_transaction" value="0">
<div class="az-toggle {{ 'off' }}" id="other_costumer_transaction_toggle"><span></span></div>
</div>
</div>
<div class="row">
<div class="col-2">
<label class="label-required" for="">No Rekening Tujuan</label>
</div>
<div class="col-10">
<select id="destination_code" class="select2 form-control destination_code" >
<option value="{{ $destination->id }}">{{ $destination->saving_code }}-{{ $destination->customer->customer_name}}-{{ $destinationType }}</option>
</select>
</div>
</div>
<div class="row" id="info-nasabah" style="display: none">
<div class="col-2">
</div>
<div class="col-10">
<h6>No. Rekening : <span id="info-kode">xxx.xxx.xxx</span></h6>
</div>
<div class="col-2">
</div>
<div class="col-10">
<h6>Nama Nasabah : <span id="info-nama">xxx.xxx.xxx</span></h6>
</div>
<div class="col-2">
</div>
<div class="col-10">
<h6>Tipe Produk : <span id="info-produk">xxx.xxx.xxx</span></h6>
</div>
<div class="col-2">
</div>
<div class="col-10">
<h6>Saldo : <span id="info-saldo">xxx.xxx.xxx</span></h6>
</div>
</div>
<div class="row">
<div class="col-2">
<label class="label-required" for="">Tanggal Autodebet</label>
</div>
<div class="col-10">
<select name="scheduled_day" id="scheduled_day" class="select2 form-control scheduled_day">
<option disabled value="{{ $data->scheduled_day }}">{{ $data->scheduled_day }}</option>
#for ($i = 1; $i <= 31; $i++)
<option class="day_option" id="day_{{ $i }}" value="{{ $i }}">{{ $i }}</option>
#endfor
</select>
</div>
</div>
<div class="row">
<div class="col-2">
<label for="saving_type_package">Keterangan</label>
</div>
<div class="col-10">
<textarea name="desc" class="form-control desc" id="" cols="30" rows="5">{{ $data->desc }}</textarea>
</div>
</div>
<div class="row">
<div class="col-2">
<label class="label-required" for="" >Status Autodebet</label>
</div>
<div class="col-10">
<input type="hidden" id="transaction_schedule_status" name="transaction_schedule_status" value="{{ $data->transaction_schedule_status ?? 1 }}">
<div class="az-toggle {{ isset($data->transaction_schedule_status) ? ($data->transaction_schedule_status == 1 ? 'on' :'') : 'on' }}" id="autodebet_status_toggle"><span></span></div>
</div>
</div>
<input type="hidden" value="" id="origin_id" name="origin_id">
<input type="hidden" class="schedule_id" id="schedule_id" name="schedule_id">
<input type="hidden" name="destination_code" id="destination_code_input">
<input type="hidden" name="origin_code" id="origin_code_input">
<div class="row">
<div class="col-12">
<div class="float-right">
<div class="btn-group">
<a href="{{admin_url('cb/tabungan/jadwal-autodebet')}}">
<button id="back_button" type="button" class="btn btn-secondary btn-block"><i class="typcn typcn-times"></i>Batalkan</button>
</a>
</div>
<div class="btn-group">
<button id="submit_button" class="btn btn-success btn-block">
<i id="loading_icon" style="display: none" class="fa fa-spin fa-spinner"></i>
<i id="submit_icon" class="typcn typcn-input-checked"></i>
Simpan</button>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</form>
how i fixed this problem?
Related
I'm new to laravel. I have to edit a form that contains a dropdown list. Edit form works fine works without the dropdown input. Updating with dropdown input throws the above error.
controller:
public function edit(QR_details $qR_detail)
{
return view('pages.edit_QR_details')->with('qr_details', $qR_detail);
}
public function update(Request $request, QR_details $qR_details)
{
$qR_details->update($request->all());
toastr()->success('QR Detail updated successfully');
return redirect()->route(('QR_code_details.index'));
}
Edit form:
form action="{{ route('QR_code_details.update', $qr_details->id) }}" method="POST" class="">
#csrf
#method("PATCH")
<div class="px-3 form-row">
<div class="form-group p-2 col-5">
<label for="" class="form-label fw-bold text-secondary">Customer Name*</label>
<select name="customer_name" class="form-select shadow" name="" id="">
#foreach ($qr_details as $qr_detail)
<option value="{{ $qr_detail->customer_name }}">{{ $qr_detail->customer_name }}</option>
#endforeach
</select>
</div>
<div class="form-group p-2 col-6">
<label for="" class="form-label text-secondary fw-bold">Background Image</label>
<input type="file" name="background image" class="form-control shadow" value="{{ $qr_details->background_image }}">
</div>
<div class="form-group p-2 col-6">
<label for="" class="form-label text-secondary fw-bold">Create QR Code</label>
<input type="file" name="create_qr_code" class="form-control shadow" value="{{ $qr_details->create_qr_code }}">
</div>
<div class="form-group p-2 col-6">
<label for="" class="form-label text-secondary fw-bold">Movable QR</label>
<input type="file" name="movable_qr" class="form-control shadow" value="{{ $qr_details->maovable_qr }}">
</div>
<div class="row ">
<div class="mt-4 col">
<button class="btn bg-gradient-danger btn-sm btn-rounded">Cancel</button>
</div>
<div class=" col mt-4">
<button class="btn bg-gradient-success btn-sm btn-rounded">Save</button>
</div>
</div>
</div>
</form>
Route:
Route::get('QR_code_detail_edit-{qR_detail}', [QRDetailsController::class, 'edit'])->name('QR_code_details.edit');
Route::post('QR_code_detail_edit-{qR_detail}', [QRDetailsController::class, 'update'])->name('QR_code_details.update');
Can someone help me out, how it should be done ?
When I try to insert data into my database, Laravel does not insert the records, but it is strange because when I migrate the tables to be able to perform the database, Laravel creates them without any problem, I do not know what I can be doing wrong if the migration run but stored no
Route:
Route::post('/proyecto', [ctrlCars::class,'store'])->name('cars');
Controler:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\cars;
class ctrlCars extends Controller
{
public function store(Request $request){
$request->validate([
'carRegistration'=> ['required','min:6'],
'name'=> ['required','min:6'],
'fromProduction' => ['required','min:6'],
'stateStored'=> ['required'],
'model'=> ['required','min:4'],
'dateAssembled' => ['required'],
]);
$car = new cars;
$car->carRegistration = $request->carRegistration;
$car->name = $request->name;
$car->fromProduction = $request->fromProduction;
$car->stateStored = $request->stateStored;
$car->model = $request->model;
$car->dateAssembled = $request->dateAssembled;
$car-> save();
return redirect()->route('cars')->with('success','Registro guardado satisfactoriamente');
}}
Template:
#extends('header')
#section('content')
<div class="container w-10 mt-5 border p-4">
<form action="{{ route('cars') }}" method="POST">
#csrf
#if (session('success'))
<h6 class="alert alert-success">{{ session('success') }}</h6>
#endif
#error('carRegistration')
<h6 class="alert alert-danger">{{ $message }}</h6>
#enderror
<p class="h2">Registro vehiculos</p>
<br>
<div class="row">
<section class="col-md-12">
<div class="form-group">
<section class="row">
<div class="col-md-4">
<label for="carRegistration" class="form-label">Placa</label>
<input type="text" class="form-control" name="carRegistration" placeholder="CDE001" maxlength="6">
</div>
<div class="col-md-4">
<label for="name" class="form-label">Nombre</label>
<input type="text" class="form-control" name="name" placeholder="Ferrari Enzo">
</div>
<div class="col-md-4">
<label for="fromProduction" class="form-label">Planta Produccion</label>
<input type="text" class="form-control" name="fromProduction" placeholder="Bmw sede1">
</div>
</section>
<section class="row mt-4">
<div class="col-md-4">
<label for="placa" class="form-label">Fecha Ensamble</label>
<input type="date" class="form-control" name="dateAssembled" placeholder="CDE001">
</div>
<div class="col-md-4">
<label for="model" class="form-label">Módelo Matricula</label>
<input type="text" class="form-control" name="model" maxlength="4" placeholder="2013">
</div>
<div class="col-md-4">
<label for="stateStored" class="form-label">Ciudad Almacenamiento</label>
<Select type="text" class="form-control" id="stateStored" placeholder="Medellin">
<option value=''>Elija una opción</option>
<option value='Medellin'>Medellín</option>
<option value="Bucaramanga">Bucaramanga</option>
<option value="Cali">Cali</option>
<option value="Bogota">Bogotá</option>
</Select>
</div>
</section>
</div>
</section>
</div>
<button type="submit" class="btn btn-success mt-4">Guardar</button>
</form>
</div>
The problem is from your template. The select tag should have a name attribute.
Change your template to this
$car->dateAssembled = $request->dateAssembled;
$car-> save();
return redirect()->route('cars')->with('success','Registro guardado satisfactoriamente');
}}
Template:
#extends('header')
#section('content')
<div class="container w-10 mt-5 border p-4">
<form action="{{ route('cars') }}" method="POST">
#csrf
#if (session('success'))
<h6 class="alert alert-success">{{ session('success') }}</h6>
#endif
#error('carRegistration')
<h6 class="alert alert-danger">{{ $message }}</h6>
#enderror
<p class="h2">Registro vehiculos</p>
<br>
<div class="row">
<section class="col-md-12">
<div class="form-group">
<section class="row">
<div class="col-md-4">
<label for="carRegistration" class="form-label">Placa</label>
<input type="text" class="form-control" name="carRegistration" placeholder="CDE001" maxlength="6">
</div>
<div class="col-md-4">
<label for="name" class="form-label">Nombre</label>
<input type="text" class="form-control" name="name" placeholder="Ferrari Enzo">
</div>
<div class="col-md-4">
<label for="fromProduction" class="form-label">Planta Produccion</label>
<input type="text" class="form-control" name="fromProduction" placeholder="Bmw sede1">
</div>
</section>
<section class="row mt-4">
<div class="col-md-4">
<label for="placa" class="form-label">Fecha Ensamble</label>
<input type="date" class="form-control" name="dateAssembled" placeholder="CDE001">
</div>
<div class="col-md-4">
<label for="model" class="form-label">Módelo Matricula</label>
<input type="text" class="form-control" name="model" maxlength="4" placeholder="2013">
</div>
<div class="col-md-4">
<label for="stateStored" class="form-label">Ciudad Almacenamiento</label>
<Select type="text" name="stateStored" class="form-control" id="stateStored" placeholder="Medellin">
<option value=''>Elija una opción</option>
<option value='Medellin'>Medellín</option>
<option value="Bucaramanga">Bucaramanga</option>
<option value="Cali">Cali</option>
<option value="Bogota">Bogotá</option>
</Select>
</div>
</section>
</div>
</section>
</div>
<button type="submit" class="btn btn-success mt-4">Guardar</button>
</form>
</div>
Thanks for help, the error come from because I call from name on the controller and in this input only have ID, and in the validation for this field have 'required';
I don't know how reply comments, but thanks aynber and Daniel L, you were nice help
First time Comment your validation section and try again. If your data successfully inserted. Then Your need to modify your required field like below.
Replace
['required','min:6']
Like this:
'required|min:6',
I'm new to Jquery. I'm building a project with Laravel 7.28. I want users to crop an image before upload. I've searched on the net but all examples upload the image right after cropping. But I want the user to crop but not upload. I want users to upload the cropped image with input fields. Here is my form and script code:
#section('content')
<div class="row">
<div class="col-lg-12 col-12">
<!-- Basic Forms -->
<div class="box">
<div class="box-header with-border">
<h4 class="box-title">Quick Offer Creation</h4>
</div>
<!-- /.box-header -->
<div class="box-body">
<div class="card-text">
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
</div>
{!! Form::open(['route'=>['quick_offer.store'], 'method' => 'POST', 'class'=> 'form', 'files' => true ]) !!}
<div class="row">
<div class="col-6">
<div class="form-group row col-md-12">
<label for="project_id" class="col-sm-2 col-form-label">Project</label>
<div class="col-sm-10">
<select name="project_id" id="" class="form-control select2">
<option value="">Please Select</option>
#foreach($projects as $project)
<option
value="{{ $project->id }}" {{ old('project_id') == $project->id ? 'selected' : '' }}>{{ $project->code . ', ' . $project->title}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group row col-md-12">
<label for="bedroom" class="col-sm-2 col-form-label">Bedroom</label>
<div class="col-sm-10">
<input class="form-control" type="text" id="bedroom" name="bedroom"
value="{{ old('bedroom') }}" min="1">
</div>
</div>
<div class="form-group row col-md-12">
<label for="location" class="col-sm-2 col-form-label">Location</label>
<div class="col-sm-10">
<input class="form-control" type="text" id="location" name="location"
value="{{ old('location') }}">
</div>
</div>
<div class="form-group row col-md-12">
<label for="status" class="col-sm-2 col-md-2 col-form-label">Status</label>
<div class="col-sm-10 col-md-10">
<select name="status" id="" class="form-control">
<option value="">Please Select</option>
<option value="publish" {{ old('status') == 'publish' ? 'selected' : '' }}>
Publish
</option>
<option value="draft" {{ old('status') == 'draft' ? 'selected' : '' }}>
Draft
</option>
<option value="review" {{ old('status') == 'review' ? 'selected' : '' }}>
Review
</option>
<option value="unpublish" {{ old('status') == 'unpublish' ? 'selected' : '' }}>
Unpublish
</option>
</select>
</div>
</div>
<div class="form-group row col-md-12">
<label for="photo" class="col-sm-2 col-form-label">
Image
<br>
<small>The photo must be square</small>
</label>
<div class="col-sm-10">
<input type="file" name="photo" class="image form-control" value="{{ old('photo') }}">
</div>
</div>
</div>
<div class="col-6">
<div class="form-group row col-md-12">
<label for="currency" class="col-sm-2 col-md-2 col-form-label">Currency</label>
<div class="col-sm-10 col-md-10">
<select name="currency" id="" class="form-control">
<option value="">Please Select</option>
<option value="TRY" {{ old('currency') == 'TRY' ? 'selected' : '' }}>
(₺) Turkish Lira
</option>
<option value="EUR" {{ old('currency') == 'EUR' ? 'selected' : '' }}>
(€) Euro
</option>
<option value="USD" {{ old('currency') == 'USD' ? 'selected' : '' }}>
($) American Dollar
</option>
<option value="GBP" {{ old('currency') == 'GBP' ? 'selected' : '' }}>
(£) GBP
</option>
</select>
</div>
</div>
<div class="form-group row col-md-12">
<label for="price" class="col-sm-2 col-form-label">Normal Price</label>
<div class="col-sm-10">
<input class="form-control" type="number" id="price" name="price"
min="0" value="{{ old('price') }}">
</div>
</div>
<div class="form-group row col-md-12">
<label for="discounted_price" class="col-sm-2 col-form-label">Discounted Price</label>
<div class="col-sm-10">
<input class="form-control" type="number" id="discounted_price"
name="discounted_price"
min="0" value="{{ old('discounted_price') }}">
</div>
</div>
<div class="form-group row col-md-12">
<label for="button_link" class="col-sm-2 col-form-label">Call to Action Link</label>
<div class="col-sm-10">
<input class="form-control" type="url" id="button_link" name="button_link"
value="{{ old('button_link') }}">
</div>
</div>
<div class="form-group row col-md-12">
<label for="company" class="col-sm-2 col-md-2 col-form-label">Company</label>
<div class="col-sm-10 col-md-10">
<select name="company" id="" class="form-control">
<option value="">Please Select</option>
<option
value="londonist_investments" {{ old('company') == 'londonist_investments' ? 'selected' : '' }}>
Londonist Investments
</option>
<option value="turyap_uk" {{ old('company') == 'turyap_uk' ? 'selected' : '' }}>
Turyap UK
</option>
</select>
</div>
</div>
</div>
<div class="col-12">
<div class="form-group row col-md-12">
<label for="key_points" class="col-md-2 col-form-label">Key Points</label>
<div class="col-md-12">
<textarea class="textarea" placeholder="One to each line"
name="key_points" id="key_points"
style="width: 100%; min-height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;">{{ old('key_points')}}</textarea>
</div>
</div>
</div>
<div class="col-12">
<div class="form-actions">
<button type="submit" class="btn btn-danger btn-lg">
<i class="fa fa-check-square-o"></i> Save
</button>
</div>
</div>
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="modalLabel"
aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalLabel">Laravel Cropper Js - Crop Image Before
Upload - Tutsmake.com</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="img-container">
<div class="row">
<div class="col-md-8">
<img id="image"
src="https://avatars0.githubusercontent.com/u/3456749">
</div>
<div class="col-md-4">
<div class="preview"></div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel
</button>
<button type="button" class="btn btn-primary" id="crop">Crop</button>
</div>
</div>
</div>
</div>
<!-- /.col -->
</div>
<!-- /.row -->
{!! Form::close() !!}
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
</div>
#endsection
#section('js')
<script>
var $modal = $('#modal');
var image = document.getElementById('image');
var cropper;
$("body").on("change", ".image", function(e){
var files = e.target.files;
var done = function (url) {
image.src = url;
$modal.modal('show');
};
var reader;
var file;
var url;
if (files && files.length > 0) {
file = files[0];
if (URL) {
done(URL.createObjectURL(file));
} else if (FileReader) {
reader = new FileReader();
reader.onload = function (e) {
done(reader.result);
};
reader.readAsDataURL(file);
}
}
});
$modal.on('shown.bs.modal', function () {
cropper = new Cropper(image, {
aspectRatio: 1,
viewMode: 3,
preview: '.preview'
});
}).on('hidden.bs.modal', function () {
cropper.destroy();
cropper = null;
});
$("#crop").click(function(){
canvas = cropper.getCroppedCanvas({
width: 800,
height: 800,
});
canvas.toBlob(function(blob) {
url = URL.createObjectURL(blob);
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function() {
var base64data = reader.result;
$.ajax({
type: "POST",
dataType: "json",
url: "crop-image-upload",
data: {'_token': $('meta[name="_token"]').attr('content'), 'image': base64data},
success: function(data){
console.log(data);
$modal.modal('hide');
alert("Crop image successfully uploaded");
}
});
}
});
})
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.5.6/cropper.js"></script>
How can I do that?
Better to do resizing in controller, using intervention/image
Package Link
Tutorial Link
Hope this will be useful.
I've got problem with dropdown list.
i want to show a primary key as a dropdown list in view blade , but i can not make the right rout to show it. Have you any ideas how to solve this problem?
this my root
$objects = ['users', 'permissions', 'roles', 'coins','pillars','subtindicators'];
foreach ($objects as $object) {
Route::get("$object", ucfirst(str_singular($object))."Controller#index")->middleware("permission:browse $object")->name("{$object}");
Route::get("$object/datatable", ucfirst(str_singular($object))."Controller#datatable")->middleware("permission:browse $object")->name("{$object}.datatable");
Route::get("$object/add", ucfirst(str_singular($object))."Controller#add")->middleware("permission:add $object")->name("{$object}.add");
Route::post("$object/create", ucfirst(str_singular($object))."Controller#create")->middleware("permission:add $object")->name("{$object}.create");
Route::get("$object/{id}/edit", ucfirst(str_singular($object))."Controller#edit")->middleware("permission:edit $object")->name("{$object}.edit");
Route::post("$object/{id}/update", ucfirst(str_singular($object))."Controller#update")->middleware("permission:edit $object")->name("{$object}.update");
Route::get("$object/{id}/delete", ucfirst(str_singular($object))."Controller#delete")->middleware("permission:delete $object")->name("{$object}.delete");
Route::get("$object/{id}", ucfirst(str_singular($object))."Controller#view")->middleware("permission:view $object")->name("{$object}.view");
Route::get("$object/create", ucfirst(str_singular($object))."Controller#list")->middleware("permission:add $object")->name("{$object}.create");
this my controller
public function add()
{ $strs = DB::table('stargets')->select('*')->get();;
return view('subtindicators.add-edit',compact('strs'));
}
public function update(Request $request, $id)
{
$object = $this->objectModel::find($id);
$object->update([
'skey_name' => $request->skey_name,
'Subtarget_base' => $request->Subtarget_base,
'Subtarget_end' => $request->Subtarget_end,
'subtarget_id' => $request->subtarget_id
]);
if ($request->save == 'browse')
return redirect()->route("{$this->objectName}");
elseif ($request->save == 'edit')
return redirect()->route("{$this->objectName}.edit", ['id' => $object]);
elseif ($request->save == 'add')
return redirect()->route("{$this->objectName}.add");
else
return redirect($request->previous_url);
}
this my blade
#extends('adminlte::page')
#include('bread.title')
#section('main-content')
<div class="container-fluid spark-screen">
<div class="row">
{!! csrf_field() !!}
<form class="form-horizontal" action="{{$actionName=='edit'?route("{$objectName}.update",['id'=>$object->id]):route("{$objectName}.create") }}" method="post">
{!! csrf_field() !!}
<input type="hidden" name="previous_url" value="{{ url()->previous() }}">
<form class="form-horizontal" action="{{ $actionName == 'edit' ? route("{$objectName}.update", ['id' => $object->id]) : route("{$objectName}.create") }}" method="post">
{!! csrf_field() !!}
<input type="hidden" name="previous_url" value="{{ url()->previous() }}">
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">{{ ucfirst($actionName) }} {{ ucfirst($objectName) }} {{ !empty($object) ? "(ID $object->id)" : '' }}</h3>
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">{{ ucfirst($actionName) }} {{ ucfirst($objectName) }} {{ !empty($object) ? "(ID $object->id)" : '' }}</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
</div>
</div>
</div>
<div class="box-body">
<div class="form-group">
<label for="" class="col-md-2 control-label">col</label>
<div class="col-md-10">
<input type="text" name="skey_name" class="form-control" maxlength="255" value="{{ !empty($object) ? $object->coin_arname : '' }}" required>
</div>
</div>
<div class="form-group">
<label for="" class="col-md-2 control-label">cl_d</label>
<div class="col-md-10">
<input type="text" name="Subtarget_base" class="form-control" maxlength="255" value="{{ !empty($object) ? $object->coin_enname : '' }}" required>
</div>
</div>
<div class="form-group">
<label for="" class="col-md-2 control-label">cl_e</label>
<div class="col-md-10">
<input type="text" name="Subtarget_end" class="form-control" maxlength="255" value="{{ !empty($object) ? $object->coin_arsymbol : '' }}" required>
</div>
</div>
<div class="form-group">
<label for="" class="form-control">c_i</label>
<div class="col-md-10">
<select class="form-control" name="starget_id">
<option selected disabled value = " ">choos</option>
#foreach($strs as $vis)
<option value="{{$vis->id}}">{{$vis->target_name}}</option>
#endforeach
<!-- <p class="form-control-static">{{ $object->subtarget_id }}</p>-->
</div>
</div>
<div class="form-group has-feedback">
<label for="title">main<span class="text-danger">*</span></label>
<select class="form-control" name="starget_id">
<option selected disabled value = " ">choos</option>
#foreach($strs as $slider2)
<option value="{{$slider2->id}}" {{ $slider2->id== $slider->starget_id ? 'selected' : '' }}>{{$slider2->vname}}</option>
#endforeach
</div>
</div>
</div>
<div class="box-footer">
#include('bread.add-edit-actions')
</div>
</div>
</form> </form>
</div>
</div>
</div>
#endsection
this error what i got
ErrorException (E_ERROR)
Undefined variable: actionName (View: C:\project Last\resources\views\bread\title.blade.php) (View: C:\Ministry Last\resources\views\bread\title.blade.php)
You should forward $actionName variable to your view:
public function add()
{
$strs = DB::table('stargets')->select('*')->get();
$actionName = 'edit';
return view('subtindicators.add-edit',compact('strs', 'actionName'));
}
However this will hardcode the form to being an "edit" form. You must see what you really want with your logic.
I can´t figure out how to edit this code in order to get all cotegories (dropdown-list-fields) being required fields. This script only validates up to 2 dropdown-list-fields before being processed and I have up to 4 categories dropdown-list-fields. Any ideas?
<!-- category select -->
<div class="form-group">
<div class="col-md-12">
<?= FORM::label('category', __('Category'), array('for'=>'category'))?>
<div id="category-chained" class="row <?=($id_category === NULL) ? NULL : 'hidden'?>"
data-apiurl="<?=Route::url('api', array('version'=>'v1', 'format'=>'json', 'controller'=>'categories'))?>"
data-price0="<?=i18n::money_format(0)?>"
<?=(core::config('advertisement.parent_category')) ? 'data-isparent' : NULL?>
>
<div id="select-category-template" class="col-md-5 hidden">
<select class="disable-chosen select-category" placeholder="<?=__('Pick a category...')?>"></select>
</div>
<div id="paid-category" class="col-md-12 hidden">
<span class="help-block" data-title="<?=__('Category %s is a paid category: %d')?>"><span class="text-warning"></span></span>
</div>
</div>
<?if($id_category !== NULL):?>
<div id="category-edit" class="row">
<div class="col-md-8">
<div class="input-group">
<input class="form-control" type="text" placeholder="<?=$selected_category->name?>" disabled>
<span class="input-group-btn">
<button class="btn btn-default" type="button"><?=__('Select another')?></button>
</span>
</div>
</div>
</div>
<?endif?>
<input id="category-selected" name="category" value="<?=$id_category?>" class="form-control invisible" style="height: 0; padding:0; width:1px; border:0;" required></input>
</div>
</div>