I have this search engine with some advanced search options but I get errors when I use advance options.
When I go to the next pages I see errors.
Here is my code:
Controller:
$Input = Input::all();
$makethis = Input::flash();
$items = Gamefarm::where('roost_hen', '=', Input::get('sex'))
->paginate(6);
return View::make('gamefarms/index', compact('items', 'makethis'));
For my views
#foreach(array_chunk($items->all(), 3) as $row)
<div class="row">
#foreach ($row as $item)
<div class="col-md-4">
<h2>{{ $item->bname}}</h2>
<img src="{{$item->img_loc}}">
<div>{{$item->desc}}</div>
</div>
#endforeach
</div>
#endforeach
{{ $items->appends(Request::except('page'))->links() }}
return View::make('gamefarms/index',compact('items','makethis'))->with('items',$items);
Related
I have a blog module in my laravel with multiple categories.In other categories pagination works just fine but with this category method links() always show the first page.This is my code:
$page = Categoriepage::where('identifiant', 'orientation')->first();
$idArticle = Articleliaison::select(array('idArticle'))->where('idPage',$page->id)->pluck('idArticle');
$articles = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->get()->take(6);
$links = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->paginate(6);
return View::make('pages.orientation')->with('articles',$articles)->with('links',$links);
and in my view:
<?php $i = 1 ?>
<div class="masonry ">
#foreach($articles as $article)
#include('components.article-or')
<?php $i++ ?>
#endforeach()
</div>
<div class="text-center" style="margin-top: 5%">
{{ $links->links() }}
</div>
You always select the first 6 articles because the articles displayed come from:
$articles = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->get()->take(6);
and not from a paginate request.
There is no need to separate the query for the links and the query for the actual articles. Instead of:
$articles = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->get()->take(6);
$links = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->paginate(6);
You can do:
$articles = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->paginate(6);
and in your view:
<div class="masonry ">
#foreach($articles as $article)
#include('components.article-or')
#endforeach
</div>
<div class="text-center" style="margin-top: 5%">
{{ $articles->links() }}
</div>
I think you got this one a bit mixed up.
You retrieve all articles (->get()) and take the first six (->take(6)). And then you retrieve $links using ->paginator(6).
This can and should all be done using just the ->paginator(6), this way Laravel retrieves the correct 6 articles for the ?page=X you are on and renders the links based on the total amount of articles found by the query.
Try it like this:
$page = Categoriepage::where('identifiant', 'orientation')->first();
$idArticle = Articleliaison::select(array('idArticle'))->where('idPage',$page->id)->pluck('idArticle');
$articles = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->paginate(6);
return View::make('pages.orientation')->with('articles',$articles)
<?php $i = 1 ?>
<div class="masonry ">
#foreach($articles as $article)
#include('components.article-or')
<?php $i++ ?>
#endforeach
</div>
<div class="text-center" style="margin-top: 5%">
{{ $articles->links() }}
</div>
you do not have to make two requests but only one
$page = Categoriepage::where('identifiant', 'orientation')->first();
$idArticle = Articleliaison::select(array('idArticle'))->where('idPage',$page->id)->pluck('idArticle');
$articles = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->paginate(6);
return View::make('pages.orientation')->with('articles',$articles);
In your view.
<div class="masonry ">
#foreach($articles as $article)
#include('components.article-or')
<?php $i++ ?>
#endforeach()
</div>
<div class="text-center" style="margin-top: 5%">
{{ $articles->links() }}
</div>
I am trying to display the given array, but I cannot seem to get my head around the dimensions of it. I am exporting data from an excel sheet then to an array.
<?php
Excel::selectSheets('active_transport_sheet_1');
$reader->formatdates(true, 'd-m-Y');
$data = $reader->get(array('project_status', 'event_area', 'date_of_event', 'area_to_split',
'planned_split', 'actual_staff_on_split_requiring_transport', 'vehicle_type_required',
'project_number', 'event_name', 'driver_responsible_person',
'hire_stauts', 'shift_start_time', 'departure_date', 'departure_time'))
->toArray();
$this->data = json_encode($data);
$this->data = json_decode($this->data, true);
Output
View
<div class="panel-body">
#foreach ($sheet as $sheets)
{{$sheets->date_of_event}}
#endforeach
</div>
Error
"Trying to get property of non-object (View:
C:\xampp\htdocs\wallboards\resources\views\boards\viewexcel.blade.php)"
<div class="panel-body">
#foreach ($sheet as $sheets)
{{$sheets->date_of_event}}
#endforeach
</div>
In the above code you are trying to access an object {{$sheets->date_of_event}} but its an array. So try $sheets['date_of_event']
So the full code is
<div class="panel-body">
#foreach ($sheet as $sheets)
{{$sheets['date_of_event']}}
#endforeach
</div>
I have read a lot into this and I am trying to find a way to refresh an HTML table in my view.
I want to use some drop down menus to select variables that are then inserted into my queries.
In my controller I have queries that populate the drop downs, and a query that is populating the table and paginating it, but I need to find out how to make the list of entries in the table change when the drop down is changed.
I have read into this quite a bit and a lot of people use javascript with onchange, but I am having trouble figuring out how to make that work with more than one drop down changing, and if possible was interested in changing the view without changing the url, but if not need some pointers or guidance on how to keep track of the variables in the url when there is more than one filter.
Edit:
View:
#extends('layouts.master')
#section('title', 'Vulnerabilities')
#section('sidebar')
#parent
#endsection
#section('content')
<div class="container">
<div class="left">
<div class="form-group"{{ $errors->has('vulns') ? ' has-error' : '' }}>
<label for="vulnerability" class="col-sm-1 control-label">Vulnerability</label>
<select class="form-control" name="cve_id" id="cve_id" onchange="javascript:location.href = this.value;">
<option value="" selected>{{ $vuln }}</option>
#foreach ($vulns as $vn)
<option value="{{ $vn->cve }}">{{ $vn->cve }}</option>
#endforeach
</select>
#if ($errors->has('vulns'))
<span class="help-block">
<strong>{{ $errors->first('vulns') }}</strong>
</span>
#endif
</div>
Vulnerable Hosts:<br/>
#foreach ($vhost as $object)
{{ $object->host }}<br/>
#endforeach
</div>
<div class="right">
Description:<br/>
#foreach ($desc as $object)
<p>{{ $object->description }}</p>
<br/>
#endforeach
Solution:<br/>
#foreach ($sltn as $object)
<p>{{ $object->solution }}</p>
<br/>
#endforeach
</div>
</div>
#endsection
Controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Item;
class VulnerabilityController extends Controller {
/**
* Return View file
*
* #var array
*/
public function Vulnerability() {
return redirect('vulnerability/CVE');
}
public function listHosts(Request $request) {
$vuln = $request->vuln;
$vhost = DB::table('items')
->select('host')
->where('cve', 'like', $vuln)
->groupBY('host')
->get();
$vulns = DB::table('items')
->select('cve')
->groupBY('cve')
->get();
$desc = DB::table('items')
->select('description')
->where('cve', 'like', $vuln)
->groupBy('description')
->get();
$sltn = DB::table('items')
->select('solution')
->where('cve', 'like', $vuln)
->groupBy('solution')
->get();
return view('vulnerability', compact('vhost', 'vulns', 'vuln', 'desc', 'sltn'));
}
}
Routes:
Route::get('vulnerability', 'VulnerabilityController#vulnerability');
Route::get('vulnerability/{vuln}', 'VulnerabilityController#listHosts');
I get errors in laravel how do I echo the values correctly. I have this multidimensional array. This is the controller:
$data = array('names'=>$names, 'fruits'=>$fruits);
return view('content', [
'data' => $data
]);
and here is where I echo the values:
#section('content')
<div class="row">
<div class="col-md-12">
#foreach ($data as $row)
{{$row['fruits']}}
#endforeach
</div>
</div>
#endsection
You can send an array with key and values to your views. The key will be the variable name in your view. This is all very basic Laravel stuff and you can read more about it in the docs.
The controller:
$data = array('names'=>$names, 'fruits'=>$fruits);
return view('content', $data);
You view:
#section('content')
<div class="row">
<div class="col-md-12">
#foreach ($fruits as $fruit)
<!-- Do stuff with $fruit -->
#endforeach
</div>
</div>
#endsection
If you want to loop over them you could do that with your original controller, but this is how it would look in your view:
#section('content')
<div class="row">
<div class="col-md-12">
#foreach ($data as $item)
{{ $item }}
#endforeach
</div>
</div>
#endsection
This will only work if $fruits and $names are convertible to strings. Otherwise you would get an error.
$data is also an array. Access it's values with the keys $data["fruits"] or $data["names"]. If you want to loop through the $fruits-array just use a foreach-loop in your template:
foreach ($data["fruits"] as $key => $value) {
// make something with the fruit-entries.
}
I can`t access the values from this variable $post from controller:
in blade view:
#foreach($post as $p)
<div class="col-md-3">
<div class="boxpromo">
<h4>{{ $p->title }}</h4>
<p>{{ $p->post_description }}</p>
<div class="price">
<div class="data">{{ $p->out_date }}</div>
<div class="cost">{{ $p->price }}</div>
</div>
</div>
</div>
#endforeach
In controller i have:
public function postSearchTransport(Request $request, Post $post){
...
// create a new query builder
$post = $post->newQuery();
// add some filters from the user in the search query
if($request->has('searchWord')){
$post->where('title', 'LIKE', '%'.$request->input('searchWord').'%');
}
...//more filters
$post->paginate(5);
return view('searchVehicle.showSearchPost')->with('post', $post);
}
What i did wrong? I should be able to access in the view all the values from the query result, but i can`t this way.
Should i convert that $post std object from controller into an array then return it to the view???
You must pass to the view the returned value of paginate method like this :
$posts = $post->paginate(5);
return view('searchVehicle.showSearchPost')->with('post', $posts);