Hello, I am learning Laravel and writing a pretty straightforward app. It is a database search application that has different views for the results (Panel View, List View, List View w/ Pics, Print View, etc.) Here's my problem:
The search bar at the top has 6 different fields, 4 of which are populated by the database itself. This search bar needs to be present on every page, in every view. How can I give this top bar its own MySQL query without having to do the SQL again for each of the queries in the different sections of my controller?
On that note, is my setup correct for this type of thing? Here's what I'm doing: the show() function is the default search view. The picsview() function is the same search but with a different results layout. the panelview() function works the same way, basically I'm taking the same input and giving different view results based on user input, and then having a different view.blade.php file for each view. Is this correct?
Thank you!
I am not quite sure I get what you are trying to do, but have you looked at View composers?
Hi, I actually managed to get what I was after by putting my queries in the BaseController.php like this:
class BaseController extends Controller {
public function __construct()
{
$bomserial = Input::get('bomserial');
$bomserials = DB::table('ph_bom_table_head')->select('serial', 'job_desc')->orderBy('serial', 'ASC')->get();
$bomsections = DB::table('ph_bom_table_sections')->select('serial', 'part_num', 'part_desc')->where('serial', '=', $bomserial)->get();
$message = "There are no results ¯\_(ツ)_/¯";
return View::share(compact('bomserials', 'bomsections', 'message', 'dateSql'));
}
Now my queries are available in all views.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community