Support the ongoing development of Laravel.io →
Database Views Blade

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!

Last updated 3 years ago.
0

I am not quite sure I get what you are trying to do, but have you looked at View composers?

http://laravel.com/docs/4.2/responses#view-composers

Last updated 3 years ago.
0
Solution

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   ¯\_(&#12484)_/¯";

	return View::share(compact('bomserials', 'bomsections', 'message', 'dateSql'));

}

Now my queries are available in all views.

Last updated 10 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

gmask gmask Joined 1 Dec 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.