I have a dropdown menu like this:
{!! Form::open(['method'=>'get']) !!}
<div class="row">
<div class="col-sm-4 form-group">
{!! Form::select('sort',[''=>'Choose Sort','asc'=>'Ascending','desc'=>'Descending'],null,['class'=>'form-control','onChange'=>'form.submit()']) !!}
</div>
<div class="col-sm-5 form-group">
<div class="input-group">
<input class="form-control" id="search"
value="{{ request('search') }}"
placeholder="Search name" name="search"
type="text" id="search"/>
<div class="input-group-btn">
<button type="submit" class="btn btn-warning">Search</button>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
When I choose a item like "Ascending", my page reloaded and the dropdown menu return into "Choose Sort". I want to keep my selected value on dropdown menu.
How can I do that? Thank you very much!
Its simple just need to pass variable
Change Your route as per your requirement
In Your View
{!! Form::open(['method'=>'get','route' => 'document.sort']) !!}
<div class="row">
<div class="col-sm-4 form-group">
{!! Form::select('sort',[''=>'Choose Sort','asc'=>'Ascending','desc'=>'Descending'],isset($sortvalues) ? $sortvalues : '',['class'=>'form-control','onChange'=>'form.submit()']) !!}
</div>
<div class="col-sm-5 form-group">
<div class="input-group">
<input class="form-control" id="search"
value="{{ request('search') }}"
placeholder="Search name" name="search" value="{{ isset($searchvalues) ? $searchvalues : ''}}"
type="text" id="search"/>
<div class="input-group-btn">
<button type="submit" class="btn btn-warning">Search</button>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
And my route
Route::any('/sort', 'DocDocumentController#sorDocument')->name('document.sort');
And finnaly in Controller
public function sorDocument(Request $request)
{
$docDocuments = DocDocument::latest()->paginate(20,['*'],'documentPage');
$searchvalues = $request->search;
$sortvalues = $request->sort;
$viewShare = array_keys(get_defined_vars());
return view('docdocuments.index', compact($viewShare));
}
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 ?
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 don't want to use "id" to edit the product, I want to use the "serial no" column. But I get the following error:
Trying to get property 'serino' of non-object
Product.php
public function edit($serino)
{
$product= DB::select('select * from products where serino=?',[$serino]);
return view("products/edit",compact("product"));
}
index.blade.php
<a href="{{route('products.edit',$product->serino)}}">
<button class="btn btn-info btn-sm"><i class="fas fa-edit"></i> Edit</button>
</a>
edit.blade.php
<form class="form-horizontal" action="{{route('products.update',$product->serino)}}" method="post">
{!! csrf_field() !!}
{!! method_field('put') !!}
<div class="form-group">
<div class="col-sm-12">
<input type="text" class="form-control" value="{{$product->name}}" name="name" placeholder="Product Name">
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<input type="text" class="form-control" value="{{$product->category}}" name="category" placeholder="Product Category">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-12">
<button type="submit" class="btn btn-success">Save</button>
</div>
</div>
</form>
Good Work..
Your query will return you collection/array of result, no just one Product.
You can use sometihing like this:
$product = DB::table('products')->where('serino', $serino)->first();
I'm making a step program and therefore I wanted to use sessions. I have a form which allows the user to fill in some information and then the input values will be put in a session array called "basic_settins" like this
public function saveSettings(Request $request, Product $products)
{
$request->session()->push('basic_settings', $request->input());
return redirect('/themes');
}
But how can I get a specific item from that array and display it for instance in my view? By using something like this: {{ Session::get('store_name') }} in an input field.
The view looks like this:
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-12">
<form method="POST" action="{{ route('saveBasicSettings') }}">
<div class="row">
<div class="col-md-12">
<button class="btn btn-primary mb-3 float-right">Next</button>
</div>
</div>
<div class="card z-depth-2" style="border-radius: 7px;">
<div class="card-body">
<input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
{{ csrf_field() }}
<div class="form-group">
<label for="store_name">Store name</label>
<input type="text" class="form-control" placeholder="Store name" id="store_name" name="store_name" value="{{ Session::get('store_name') }}" required>
</div>
<div class="form-group">
<label for="company name">Company name</label>
<input type="text" class="form-control" placeholder="Company name" id="company_name" name="company_name" value="{{ Session::get('company_name') }}" required>
</div>
<div class="form-group">
<label for="company_tel">Company phonenumber</label>
<input type="text" class="form-control" placeholder="Company Phonenumber" id="company_tel" name="company_tel" value="{{ Session::get('company_tel') }}" required>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
#endsection
When I dd the request by doing this: $data = $request->session()->all(); and then dd($data);
I get the following result:
How can I make this work? Thanks in advance!
When you're using push(), an array will be created, so you need to do something like this:
{{ session('basic_settings.0.company_name') }}
Or:
{{ session('basic_settings')[0]['company_name'] }}
But I would recommend you to save the data with:
{{ session(['basic_settings' => request()->all()]) }}
Then you'll be able to read it with:
{{ session('basic_settings.company_name') }}
i am new for laravel.this is my view form
<div class="row">
<div class="col-md-6">
<form class="" action="{{route('production.update', $rm->id)}}" method="post">
<input name="_method" type="hidden" value="PATCH">
{{csrf_field()}}
<input type="hidden" name="id" id="id" class="form-control" value="{{$rm->id}}">
<div class="form-group{{ ($errors->has('batch_id')) ? $errors->first('title') : '' }}">
<lable>Batch ID</lable>
<input type="text" name="batch_id" id="batch_id" class="form-control" value="{{$rm->product_id}}" readonly="">
{!! $errors->first('wastage','<p class="help-block">:message</p>') !!}
</div>
<div class="form-group{{ ($errors->has('')) ? $errors->first('title') : '' }}">
<lable>Packing</lable>
#foreach($subitem as $sub)
<div class="row">
<div class="col-md-4">
<input type="checkbox" name="subitem[i]" value="{{$sub->id}}"> {{$sub->subitem_name}}
<div class="col-md-4">
<input type="text" name="qty[i]" id="qty" class="form-control" placeholder="Entire Qty">
{!! $errors->first('qty','<p class="help-block">:message</p>') !!}
</div>
</div>
#endforeach
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Add">
</div>
</form>
</div>
</div>
</div>
i need to do, when i click the add button, insert batch_id, sub_id and quantity to multiples rows.batch_id is same and quantity, sub_id are difference.please can anyone help me to do it ?
i need to change my controller also,
public function update(Request $request, $id)
{
$items = new Itempacking;
$items->batch_id = $request->batch_id;
$items->sub_id = $request->sub_id
$items->quantity = $request->quantity;
$items->save();
}
anyone can help for this ?
Change you form element like this
#foreach($subitem as $sub)
<div class="row">
<div class="col-md-4">
<input type="checkbox" name="subitem[{{$sub->id}}][id]" value="{{$sub->id}}"> {{$sub->subitem_name}}
<div class="col-md-4">
<input type="text" name="subitem[{{$sub->id}}][qty]" value="{{$sub->qty}}}" class="form-control" placeholder="Entire Qty">
{!! $errors->first('qty','<p class="help-block">:message</p>') !!}
</div>
</div>
#endforeach
Loop the $request->subitem like this
`
public function update(Request $request, $id)
{
foreach($request->subitem as $key=>$row)
{
$items = new Itempacking;
$items->batch_id = $request->batch_id;
$items->sub_id = $row['id']
$items->quantity = $row['qty'];
$items->save();
$items='';
}`