Anyone can help ? at least please tell how to get the value of 'keyword' that user entered from view ??
<button class="submit" type="submit" onclick="location.href='{{ action('CompanyController@listCompany') }}'"> Search</button>
thanks!
What I do:
if(isset($_REQUEST['t1']))
{
$t1 = $_REQUEST['t1'];
}
else
{
$t1 = "";
}
$ownersearch = $t1;
$ownersearch = $ownersearch . "%";
//$ownersearch = "j";
//$ownersearch = $ownersearch . "%";
//
$data['owners'] = DB::table('powners')
->where('oname', 'like', $ownersearch)
->orderBy('oname', 'asc')
->Paginate(5);
$data['osearch'] = $t1; //needs passing each time for querystring/pagination
Then pass to view like:
return View::make('owner/pownerlist')->with('data', $data['owners'])->with('data2', $data['osearch']);
Of course intial search comes from a search form with whatever parameters need passed, like searchby. These params are added as needed in your application.
Probably a better way, but this is what I do. Also you can change $_REQUEST to $_POST.
Thanks jimgwhit, but i still cant get what i want, the $data['owners'] is same with $companys right ?
and in my controller i return View::make('company.listcompany', compact('companys','sortby', 'order')) ; like that, means i already pass the companys to view ?
i not und:
->with('data2', $data['osearch'] whats means ?
and
$data['osearch'] = $t1; whats osearch represent ?
thanks again
return View::make('owner/pownerlist')->with('data', $data['owners'])->with('data2', $data['osearch']);
'data', $data['owners'] is the resultset, and 'data2', $data['osearch'] and extras for query string/pagination read and watch video on pagination and passing extra info. view (didn't use blade, but you can convert all to blade, same idea):
<body>
<div>
owners
<form method="get" action="owners">
<label>sch</label><input type="text" name="t1" value=""> <input type="submit" name="submit" value="Search">
</form>
</div>
<div style="margin-left: 20px; margin-right: auto; width: 800px; border:solid red; display:block;">
<table id="myTable">
<thead style="background-color:lightblue">
<tr>
<th>ownerid</th>
<th>oname</th>
</tr>
</thead>
<?php
echo "<br>";
foreach ($data as $owner){
//echo $owner['oname'];//works with ORM also
//echo $owner->oname; //use with database and querybuilder and ORM
echo "<tr>";
echo "<td>"."<a href=\"\" >".$owner->ownerid."</a>"."</td>";
echo "<td>"."<a>".$owner->oname."</a>"."</td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
//echo $data->links();
echo '<br>';
//echo $users->appends(array('sort' => 'votes'))->links();
?>
<!--<div style="clear:both; "></div>-->
<div class="pagination" style="margin-left: 20px; margin-right: auto; width: 800px; border:solid red; display: block;">
<?php echo $data->appends(array('t1' => $data2))->links(); ?> ////t1 added to links read about pagination
</div>
</body>
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community