Losing page number on form post laravel - php

I have two dropdowns one for asc desc and one with the field name. When I change page I am able to keep the order and order_by parameter and the page number. When I change one of the dropdown a postback happens In that case I lose the page number. How can I fix this problem.
Here is the url I want
home?orderby=created_at&order=desc&page=2
Here is the url I have in the case of a dropdown change
home?orderby=created_at&order=desc
Here is my front end code
<form action="{{ route('home') }}" method="GET">
<div class="row">
<div class="col-2">
<label for="nom">Trier par :</label>
</div>
<div class="col-tier form-group">
<select class="form-control" name="orderby" id="orderby" onchange="this.form.submit()">
<option value="nom" {{ Request()->orderby == 'nom' ? ' selected' : '' }}>Nom</option>
<option value="created_at" {{ Request()->orderby == 'created_at' ? ' selected' : '' }}>Date de création</option>
<option value="updated_at" {{ Request()->orderby == 'updated_at' ? ' selected' : '' }}>Date de modification</option>
</select>
</div>
<div class="col-tier form-group ">
<select class="form-control" name="order" id="order" onchange="this.form.submit()">
<option value="desc" {{ Request()->order == 'desc' ? ' selected' : '' }}>Desc</option>
<option value="asc" {{ Request()->order == 'asc' ? ' selected' : '' }}>Asc</option>
</select>
</div>
</div>
</form>
<div id="pagination" class="d-flex justify-content-center">
{{ $grilles->appends(request()->except('page'))->links() }}
</div>
Here is the code of the controlleur
public function index(Request $request)
{
$user = Auth::user();
$sort = "ASC";
if($request->get('order')==="desc")
{
$sort="DESC";
}
if ($request->get('orderby')==="created_at") {
$grilles = Grille::orderBy('created_at', $sort)->paginate(15)->appends(request()->query());
} else if ($request->get('orderby')==="updated_at") {
$grilles =Grille::orderBy('updated_at', $sort)->paginate(15)->appends(request()->query());
}
else{
$grilles =Grille::orderBy('nom', $sort)->paginate(15)->appends(request()->query());
}
return view('home', compact('grilles'));
}
<div id="pagination" class="d-flex justify-content-center">
{{ $grilles->appends(request()->except('page'))->links() }}
</div>

Related

blade file : $meeting is undefined

Whenever I visit the add-meeting URL, I receive an error message stating that $meeting is undefined. However, when I attempt to edit a meeting, everything works as expected. I am using the same blade file for both creating and updating meetings. Can you explain why this error is occurring?
Here is MeetingController:
public function add_meeting()
{
$customers = Customer::all();
$projects = Project::all();
return view('admin.meeting.add-meeting', get_defined_vars());
}
public function store(Request $request)
{
$this->validate($request, [
'meeting_scedule' => 'required',
'meeting_user_id' => 'required',
'project_id' => 'required',
'agenda' => 'required',
]);
if ($request->id) {
$input['meeting_scedule'] = $request->meeting_scedule;
$input['meeting_user_id'] = $request->meeting_user_id;
$input['project_id'] = $request->project_id;
$input['agenda'] = $request->agenda;
$meeting = Meeting::where('id', $request->id)->update($input);
return back()->with('success', 'Updated Successfully!');
} else {
$new['meeting_scedule'] = $request->meeting_scedule;
$new['meeting_user_id'] = $request->meeting_user_id;
$new['project_id'] = $request->project_id;
$new['agenda'] = $request->agenda;
$meeting = new Meeting();
$meeting->persist($new);
return back()->with('success', 'Meeting Created Successfully!');
}
}
public function edit_meeting($id)
{
$customers = Customer::all();
$projects = Project::all();
$meeting = Meeting::find($id);
return view('admin.meeting.add-meeting', get_defined_vars());
}
Here is add-meeting.blade.php file:
<form action="{{url('admin/update-meeting')}}" method="POST" id="add-rel-form"
enctype="multipart/form-data">
#csrf
#if(isset($meeting))
<input class="hidden" type="hidden" name="id" value="{{$meeting->id ?? ''}}">
#endif
<div class="form-row">
<div class="form-group col-md-6 mb-0">
<label> Meeting Schedule</label>
<div class="form-group">
<input type="datetime-local" value="{{$meeting->meeting_scedule ?? ''}}" required
class="form-control" name="meeting_scedule" id="meeting_scedule">
</div>
</div>
<div class="form-group col-md-6 mb-0">
<label> User</label>
<select id="customer-select" class='form-control' required name="meeting_user_id">
<option value="" id="">--Select User--</option>
#foreach($customers as $customer)
<option value="{{$customer->id}}"{{ $customer->id == $meeting->meeting_user_id ? 'selected' : '' }}>{{$customer->first_name." ".$customer->last_name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6 mb-0">
<label> Project</label>
<select id="project-select" class='form-control' required name="project_id" disabled>
<option value="" id="">--Select Project--</option>
#foreach($projects as $project)
<option value="{{$project->id}}"{{$project->id == $meeting->project_id ? 'selected' : ''}}>{{$project->project_type}}</option>
#endforeach
</select>
</div>
<div class="form-group col-md-6 mb-0">
<label> Agenda</label>
<div class="form-group">
<textarea type="text" value="" required
class="form-control" name="agenda" id="agenda">{{$meeting->agenda ?? ''}}</textarea>
</div>
</div>
</div>
Since there is no $meeting variable when creating a new meeting, the error occurs.
You can use null coalescing operator (??) or ternary operator (?:) to check if $meeting is defined before attempting to access its properties :
#if(isset($meeting))
<input class="hidden" type="hidden" name="id" value="{{$meeting->id}}">
#endif
...
<select id="customer-select" class='form-control' required name="meeting_user_id">
<option value="" id="">--Select User--</option>
#foreach($customers as $customer)
<option value="{{$customer->id}}" {{ isset($meeting) && $customer->id == $meeting->meeting_user_id ? 'selected' : '' }}>{{$customer->first_name." ".$customer->last_name}}</option>
#endforeach
</select>
...
<select id="project-select" class='form-control' required name="project_id" disabled>
<option value="" id="">--Select Project--</option>
#foreach($projects as $project)
<option value="{{$project->id}}"{{ isset($meeting) && $project->id == $meeting->project_id ? 'selected' : ''}}>{{$project->project_type}}</option>
#endforeach
</select>
...
<textarea type="text" value="" required class="form-control" name="agenda" id="agenda">{{ isset($meeting) ? $meeting->agenda : '' }}</textarea>

Store data again with the same id Laravel

I want to create an order with multiple articles, so first I made a blade where you can create an order, and then you press on forward to get on another blade where you can submit articles for that order created, so on the second blade I've made 3 buttons down, one to submit and leave, the other one is to submit and add another article, and the other one is submit and create a new order.
So my submit and add article button doesn't work properly because i don't get the order_id (foreign of id of the order). Maybe a mistake in my controller function
Here is my code
Create order blade
<div class="form-group">
<label>Bestelnummer</label>
<div class="input-group">
<input type="text" name="ordernumber" class="form-control"
placeholder="Vul bestelnummer in (653...)"
value="{{ old('ordernumber') }}">
</div>
</div>
<div class="form-group">
<label>HB Ordernumber</label>
<input type="text" name="hbnumber" class="form-control"
placeholder="Vul HB Ordernummer in" value="{{ old('hbnumber') }}">
</div>
<div class="form-group">
<label>Klantnaam</label>
<input type="text" name="customername" class="form-control"
placeholder="Vul klantnaam in" value="{{ old('customername') }}">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success" name="submit_order" value="submit">Doorgaan
</button>
</div>
And this is the function in the controller of the create
$retourorder = new Returnorder();
$retourorder->firmaname = request('firmaname');
$retourorder->contactperson = request('contactperson');
$retourorder->email = request('email');
$retourorder->ordernumber = request('ordernumber');
$retourorder->hbnumber = request('hbnumber');
$retourorder->customername = request('customername');
$retourorder->save();
$admin = \request()->get('admin');
return view ('retour.create_articles', ['retourOrder' => $retourorder, 'admin' => $admin]);
Create_articles blade
<div class="form-group">
<label for="order_id" >Bestelnummer</label>
<select name="order_id" class="form-control" >
<option
value="{{ $retourOrder->id }}" {{ old('order_id') == $retourOrder->ordernumber ? 'selected' : '' }} > {{ $retourOrder->ordernumber }} </option>
</select>
</div>
<div class="form-group">
<label>Artikelnummer</label>
<input type="text" name="articlenumber" class="form-control"
placeholder="Vul artikelnummer in" value="{{ old('articlenumber') }}">
</div>
<div class="form-group">
<label>Retour aantal</label>
<input type="text" name="return_quantity" class="form-control"
placeholder="Vul retour aantal in"
value="{{old('return_quantity')}}">
</div>
<div class="form-group">
<label>Kwaliteit retour</label>
<select name="return_quality" class="form-control">
<option value="1" {{ old('return_quality') == 1 ? 'selected' : '' }} >Verkoopbaar</option>
<option value="2" {{ old('return_quality') == 2 ? 'selected' : '' }} >Niet verkoopbaar</option>
</select>
</div>
<div class="form-group">
<label>Teruggave reden volgens retourbewijs</label>
<select name="return_reason" class="form-control">
<option value="1" {{ old('return_reason') == 1 ? 'selected' : '' }} >Levertijd</option>
<option value="2" {{ old('return_reason') == 2 ? 'selected' : '' }} >Kwaliteit</option>
<option value="3" {{ old('return_reason') == 3 ? 'selected' : '' }} >Defect</option>
<option value="4" {{ old('return_reason') == 4 ? 'selected' : '' }} >Overig</option>
<option value="5" {{ old('return_reason') == 5 ? 'selected' : '' }} >Aanname geweigerd</option>
<option value="6" {{ old('return_reason') == 6 ? 'selected' : '' }} >Adres ontvanger onbekend
</option>
</select>
</div>
<div class="form-group">
<label for="inputGroupFile01">Upload foto (Maximaal 1 foto)</label>
<input type="file" name="image" class="form-control-file"
id="inputGroupFile01"
aria-describedby="inputGroupFileAddon01">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success" name="submit" value="submit">Verstuur
</button>
<button type="submit" class="btn btn-secondary"
name="submit" value="submit_again">Nieuw artikel
</button>
<button type="submit" class="btn btn-danger"
name="submit" value="submit_new">Verstuur & Nieuwe retourmelding
</button>
Controller function of create_articles
if ($request->hasFile('image')) {
$filenameWithExt = $request->file('image')->getClientOriginalExtension();
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
$extension = $request->file('image')->getClientOriginalExtension();
$fileNameToStore = $filename . '_' . time() . '.' . $extension;
$request->file('image')->move('storage/images', $fileNameToStore);
} else {
$fileNameToStore = 'noimage.jpg';
}
$retourartikel = new Returnarticles();
$retourartikel->order_id = request('order_id');
$retourartikel->articlenumber = request('articlenumber');
$retourartikel->return_quantity = request('return_quantity');
$retourartikel->return_quality = request('return_quality');
$retourartikel->return_reason = request('return_reason');
$retourartikel->images = $fileNameToStore;
$retourartikel->save();
$admin = \request()->get('admin');
if ($request->submit === 'submit') {
return redirect('/retour')->with('message', 'Je retourmelding is succesvol verzonden');
} elseif ($request->submit === 'submit_again') {
return view('retour.create_articles', ['retourOrder' => $retourartikel, 'admin' => $admin])->with('message', 'Je kunt nu een ander artikelnummer toevoegen')->withInput($request->only('order_id'));
} else {
return redirect('/retour/create')->with('message', 'Je retourmelding is succesvol verzonden, je kunt nu een nieuwe retourmelding maken');
}

Why did not update table columns values in Laravel 5.6?

in laravel 5.6 app I have table name as vehicles, then I need update some of table values in VehicleController update function as this,
public function update(Request $request, $id)
{
$vehicle = Vehicle::find($id);
$vehicle->provincename = $request->input('provincename');
$vehicle->districtname = $request->input('districtname');
$vehicle->townname = $request->input('townname');
$vehicle->brandname = $request->input('brandname');
$vehicle->modelname = $request->input('modelname');
$vehicle->modelyear = $request->input('year');
$vehicle->condition = $request->input('condition');
$vehicle->milage = $request->input('milage');
$vehicle->detail = $request->input('data');
$vehicle->price = $request->input('price');
$vehicle->telephone = $request->input('telephone');
$vehicle->categoryname = $request->input('categoryname');
$vehicle->transmission = $request->input('transmission');
$vehicle->fueltype = $request->input('fueltype');
$vehicle->enginecapacity = $request->input('enginecapacity');
$vehicle->user_id = Auth::user()->id;
$vehicle->save();
and edit form action is,
<form method="post" action="{{ route('vehicles.edit', [$vehicles->id]) }}" enctype="multipart/form-data">
and update route is,
Route::post('myads/{id}', [
'uses' => '\App\Http\Controllers\VehicleController#update',
])->name('vehicles.edit');
and controller edit function,
public function edit($id)
{
$vehicles = Vehicle::findOrFail($id);
}
and edit route is,
Route::get('myads/{id}/edit', [
'uses' => '\App\Http\Controllers\VehicleController#edit',
'as'=> 'vehicles.edit'
]);
but when I click update button it did not update values. no any error occurred here only redirect back to edit form. how can fix this problem?
vehicle model
class Vehicle extends Model
{
use Searchable;
protected $guarded = [];
public function searchableAs()
{
return 'categoryname';
}
public function category()
{
return $this->belongsTo(Category::class);
}
public function uploads()
{
return $this->hasMany(Upload::class);
}
public function cars()
{
return $this->hasMany(Car::class);
}
public function vans()
{
return $this->hasMany(Car::class);
}
public function scopePersonal($query)
{
return $query->where('user_id', Auth::user()->id);
}
}
edit form is,
<form method="post" action="{{ route('vehicles.edit', [$vehicles->id]) }}" enctype="multipart/form-data">
{{csrf_field()}}
<div class="form-group{{ $errors->has('provincename') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1">Province</label>
<select name="provincename" id="provincename" class="form-control input dynamic" data-dependent="districtname" >
<option value="{{$vehicles->provincename}}">{!! $vehicles->provincename !!}</option>
#foreach($town_list as $town)
<option value="{{$town->provincename}}">{{$town->provincename}}</option>
#endforeach
</select>
#if ($errors->has('provincename'))
<span class="help-block">{{ $errors->first('provincename') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('districtname') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1">District</label>
<select name="districtname" id="districtname" class="form-control input dynamic" data-dependent="townname" >
<option value="{{$vehicles->districtname}}">{!! $vehicles->districtname !!}</option>
</select>
#if ($errors->has('districtname'))
<span class="help-block">{{ $errors->first('districtname') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('townname') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1">Town</label>
<select name="townname" id="townname" class="form-control input">
<option value="{{$vehicles->townname}}">{!! $vehicles->townname !!}</option>
</select>
#if ($errors->has('townname'))
<span class="help-block">{{ $errors->first('townname') }}</span>
#endif
</div>
<!--hidden select box-->
<div class="form-group" style="display: none;">
<label for="exampleFormControlSelect1">Vehicle Category</label>
<select name="categoryname" id="categoryname" class="form-control input dynamic" data-dependent="brandname" >
#foreach($model_list as $model)
<option value="{{$vehicles->categoryname}}">{{$vehicles->categoryname}}</option>
#endforeach
</select>
</div>
<div class="form-group{{ $errors->has('brandname') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1">Brand</label>
<select name="brandname" id="brandname" class="form-control input dynamic" data-dependent="modelname" >
<option value="{{$vehicles->brandname}}">{!! $vehicles->brandname !!}</option>
</select>
#if ($errors->has('brandname'))
<span class="help-block">{{ $errors->first('brandname') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('modelname') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1">Model</label>
<select name="modelname" id="modelname" class="form-control input">
<option value="{{$vehicles->modelname}}">{!! $vehicles->modelname !!}</option>
</select>
#if ($errors->has('modelname'))
<span class="help-block">{{ $errors->first('modelname') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('year') ? ' has-error' : '' }}">
<label for="formGroupExampleInput">Model Year</label>
<input type="text" class="form-control" id="year" placeholder="Year" name="year" value="{!! $vehicles->modelyear ?: '' !!}">
#if ($errors->has('year'))
<span class="help-block">{{ $errors->first('year') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('condition') ? ' has-error' : '' }}">
<label for="formGroupExampleInput">Condition</label>
<label class="radio-inline"><input type="radio" name="condition" value="used" #if($vehicles->condition == 'used') checked #endif>Used</label>
<label class="radio-inline"><input type="radio" name="condition" value="recondition" #if($vehicles->condition == 'recondition') checked #endif>Recondition</label>
<label class="radio-inline"><input type="radio" name="condition" value="new" #if($vehicles->condition == 'new') checked #endif> New</label>
#if ($errors->has('condition'))
<span class="help-block">{{ $errors->first('condition') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('milage') ? ' has-error' : '' }}">
<label for="formGroupExampleInput">Milage</label>
<input type="text" class="form-control" id="milage" placeholder="Milage" name="milage" value="{!! $vehicles->milage ?: '' !!}">
#if ($errors->has('milage'))
<span class="help-block">{{ $errors->first('milage') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('transmission') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1">Transmission</label>
<select class="form-control" id="transmission" name="transmission">
<option value="{!! $vehicles->transmission !!}">{!! $vehicles->transmission !!}</option>
<option value="Manual">Manual</option>
<option value="Auto">Auto</option>
<option value="Hybrid">Hybrid</option>
<option value="Electric">Electric</option>
<option value="Codak">codak</option>
</select>
#if ($errors->has('transmission'))
<span class="help-block">{{ $errors->first('transmission') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('fueltype') ? ' has-error' : '' }}">
<label for="exampleFormControlSelect1">Fuel Type</label>
<select class="form-control" id="fueltype" name="fueltype">
<option value="{!! $vehicles->fueltype !!}">{!! $vehicles->fueltype !!}</option>
<option value="Petrol">Petrol</option>
<option value="Diesel">Diesel</option>
<option value="Hybrid">Hybrid</option>
<option value="Electric">Electric</option>
</select>
#if ($errors->has('fueltype'))
<span class="help-block">{{ $errors->first('fueltype') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('enginecapacity') ? ' has-error' : '' }}">
<label for="formGroupExampleInput">Engine capacity</label>
<input type="text" class="form-control" id="enginecapacity" placeholder="Engine capacity" name="enginecapacity" value="{!! $vehicles->enginecapacity ?: '' !!}" >
#if ($errors->has('enginecapacity'))
<span class="help-block">{{ $errors->first('enginecapacity') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('data') ? ' has-error' : '' }}">
<label for="comment">More Details</label>
<textarea class="form-control" rows="5" id="data" name="data" rows="10" cols="10">{!! trim($vehicles->detail) !!}</textarea>
#if ($errors->has('data'))
<span class="help-block">{{ $errors->first('data') }}</span>
#endif
</div >
<div class="form-group{{ $errors->has('price') ? ' has-error' : '' }}">
<label for="formGroupExampleInput">Price</label>
<input type="text" class="form-control" id="price" placeholder="Price" name="price" value="{!! $vehicles->price ?: '' !!}">
#if ($errors->has('price'))
<span class="help-block">{{ $errors->first('price') }}</span>
#endif
</div>
<div class="form-group{{ $errors->has('telephone') ? ' has-error' : '' }}">
<label for="formGroupExampleInput">Telephone</label>
<input type="text" class="form-control" id="telephone" placeholder="Telephone" name="telephone" value="{!! $vehicles->telephone ?: '' !!}" >
#if ($errors->has('telephone'))
<span class="help-block">{{ $errors->first('telephone') }}</span>
#endif
</div>
<!-- <button type="submit" class="btn btn-primary" style="margin-top:10px">Submit</button>
</div> -->
#if( $vehicles->uploads->count() > 0 )
#php
$upload = $vehicles->uploads->sortByDesc('id')->first();
#endphp
<!-- <img id="preview" src="/images/{{ $upload->resized_name }}"> -->
<!--edit/delete buttons-->
#foreach( $vehicles-> uploads as $upload)
<img id="preview"
src="{{asset((isset($upload) && $upload->resized_name!='')?'images/'.$upload->resized_name:'images/noimage.png')}}"
height="200px" width="200px"/>
<input class="form-control" style="display:none" name="files[]" type="file" id="files" name="_token" value="{{ csrf_token() }}" enctype="multipart/form-data">
<br/>
<!-- Add Image | -->
<!-- <a style="color: red" href="javascript:removeImage()">Delete</a>
<input type="hidden" style="display: none" value="0" name="remove" id="remove"> -->
Edit Image|
<a class="button is-outlined" href="/myads/{{$upload->id}}/delete" onclick="return confirm('Are you sure to want to delete this record?')" >Delete</a></td>
<hr>
#endforeach
#endif
<button type="submit" class="btn btn-primary" style="margin-top:10px">Submit</button>
</div>
There will be mutiple reasons
1. You are not passing the csrf token with form request.
2. There will be one or more input value missing and you have not show the error message in the validation.
3. Vehicle id not exist.
etc.
try this way
and remove or comment this lines below
//$vehicle->save();
$vehicle = array('provincename'=>$request->input('provincename'),
'districtname' => $request->input('districtname'),
'townname' => $request->input('townname'),
'brandname' => $request->input('brandname'),
'modelname' => $request->input('modelname'),
'modelyear' => $request->input('year'),
'condition' => $request->input('condition'),
'milage' => $request->input('milage'),
'detail' => $request->input('data'),
'price' => $request->input('price'),
'telephone' => $request->input('telephone'),
'categoryname' => $request->input('categoryname'),
'transmission' => $request->input('transmission'),
'fueltype' => $request->input('fueltype'),
'enginecapacity' => $request->input('enginecapacity'),
'user_id' => Auth::user()->id);
Vehicle::where('id', $id)->update($vehicle);
You can use array to update your record and also make sure to pass csrf token when submitting a data. Add user_id column to the array.
DB::table('vehicles')
->where('id', $vehicle)
->update(['provincename ' => $request->input('provincename'),
'districtname'=>$request->input('districtname'),
'townname' =>input('townname'), 'user_id'=>Auth::user()->id ]);

Why the message dont hide when there are results?

I have a page that has 4 select menus for the user filter conferences based on the conference category, city, price and date.
But if the selection of the user dont return any result should appear a message "There are no results for your search", and it works , the message appear. However there is an issue, for example the user does a selection that dont return any result, the message appears, but then if the user do another selection that returns results, the results appear but the message dont hide, the message still appears saying that there are no results.
Do you know why the message appear?
HTML:
#if($flash = session('no_conferences'))
<div class="alert alert-danger" role="alert">
<strong><i class="fa fa-check-circle" aria-hidden="true"></i></strong>
{{ $flash }}
</div>
#endif
<form action="{{ route('search.index') }}" method="get">
{{csrf_field()}}
<div class="row">
<div class="col-6 col-md-3 mb-4 mb-md-0">
<select class="custom-select form-control font-size-xsm text-gray searchSelect"
name="category_id">
<option selected="" value="">All categories</option>
#foreach ($categories as $category)
<option value="{{ $category->id }}"
{{ (!empty($categoryId) && $categoryId == $category->id) ? 'selected' : '' }}>
{{ $category->name }}
</option>
#endforeach
</select>
</div>
<div class="col-6 col-md-3 mb-4 mb-md-0">
<select class="custom-select form-control"
name="city">
<option selected="" value="">Country</option>
#foreach($cities as $city)
<option value="{{ $city }}" {{ (!empty($selectedCity) && $selectedCity == $city) ? 'selected' : '' }}>
{{ $city }}
</option>
#endforeach
</select>
</div>
<div class="col-6 col-md-3">
<select class="custom-select form-control font-size-xsm"
name="price">
<option value="paid" {{ (!empty($price) && $price == 'paid') ? 'selected' : '' }}>
Paid
</option>
<option value="free" {{ (!empty($price) && $price == 'free') ? 'selected' : '' }}>
Free
</option>
</select>
</div>
<div class="col-6 col-md-3">
<select class="custom-select form-control"
name="range">
<option value="day" {{ (!empty($range) && $range == 'day') ? 'selected' : '' }}>
Tody
</option>
<option value="week" {{ (!empty($range) && $range == 'week') ? 'selected' : '' }}>
This Week
</option>
</select>
</div>
</div>
</form>
SearchController
class SearchController extends Controller
{
public function index(Request $request){
$categoryId = $request->get('category_id');
$city = $request->get('city');
$price = $request->get('price');
$range = $request->get('range');
$pageLimit = 8;
$conference = Conference::Query()->where('status', 'P');
if(!empty($categoryId)) {
$conference = $conference->whereHas('categories', function($qry) use($categoryId) {
$qry->where('category_id', $categoryId);
});
}
if(!empty($city)) {
$conference = $conference->where('city', $city);
}
if(!empty($price)) {
if($price == "free") {
$conference = $conference->whereHas('registrationTypes', function($qry) {
$qry->where('price', '=', 0);
});
} elseif($price == "paid") {
$conference = $conference->whereHas('registrationTypes', function($qry) {
$qry->where('price', '>', 0);
});
}
}
if(!empty($range)) {
if($range == "week") {
$conference = $conference->where('start_date', '<', Carbon::now()->addDays(7));
}
elseif($range == "day") {
$conference = $conference->whereDate('start_date', '=', Carbon::today()->format('Y-m-d'));
}
}
$conference = $conference->orderBy('created_at','desc')->paginate($pageLimit);
if(count($conference) == 0){
Session::flash('no_conferences', 'There are no results for your search
');
}
return view('search', [
'categories' => Category::orderBy('created_at', 'desc')->get(),
'cities' => Conference::orderBy('created_at','desc')->pluck("city")->unique(),
'conferences' => $conference,
'categoryId' => $categoryId,
'selectedCity' => $city,
'price' => $price,
'range' => $range,
]);
}
}
This assignment will always return true.
#if($flash = session('no_conferences'))
Try changing your view condition to this:
#if(Session::has('no_conferences'))
<div class="alert alert-danger" role="alert">
<strong><i class="fa fa-check-circle" aria-hidden="true"></i></strong>
{{ Session::get('no_conferences') }}
</div>
#endif
Or you could just use something like this in your view and remove the session flash in your controller altogether.
#unless (count($conferences))
<div class="alert alert-danger" role="alert">
<strong><i class="fa fa-check-circle" aria-hidden="true"></i></strong>
There are no results for your search
</div>
#endunless

In laravel based on the dropdown list selected value make the check box as read only field

I have ui that contains dropdown list and check box.Based on the drop downlist selection value i want compare with the isnesd field(it is one more field in the database),based on that comparison i want to make check box as read only field.
view:
<!-- Asset Type -->
<div class="form-group {{ $errors->has('asset_type_id') ? ' has-error' : '' }}">
<label for="asset_type_id" class="col-md-3 control-label">#lang('admin/assetdetails/form.type')</label>
<div class="controls col-md-7">
<div class="field-box">
{{ Form::select('asset_type_id',$assettype_list, Input::old('asset_type_id'), array('class'=>'select2', 'onchange' => 'check(this.value)' ,'style'=>'width:350px')) }}
{{ $errors->first('asset_type_id', '<span class="alert-msg"><i class="icon-remove-sign"></i> :message</span>') }}
</div>
</div>
</div>
<!-- NESD -->
<div class="form-group {{ $errors->has('nesd') ? 'error' : '' }}">
<label for="nesd" class="col-md-3 control-label">#lang('admin/assetdetails/form.nesd')</label>
<div class="controls col-md-7">
<input class="col-md-1 controls isnesdbox" type="checkbox" name="nesd" id="nesd" value="1" {{ $assetdetail->nesd === '1' ? 'checked' : '' }} />
{{ $errors->first('nesd', '<span class="alert-msg"><i class="icon-remove-sign"></i> :message</span>') }}
</div>
</div>
controller:
public function getCreate()
{
$location_list = array('' => '') + Location::lists('name', 'id');
$assettype_list = array('' => '') + Assettype::lists('asset_type', 'id');
// Show the page
$assetdetail_options = array('0' => 'Top Level') + Assetdetail::lists('asset_number','id');
return View::make('backend/assetdetails/edit')->with('assetdetail_options',$assetdetail_options)->with('assetdetail',new Assetdetail)->with('location_list',$location_list)->with('assettype_list',$assettype_list);
}

Categories