Support the ongoing development of Laravel.io →
Database Views Blade
Last updated 2 years ago.
0

First of all check if your view composer code is being called by dd() before the View::composer. Second thing, this composer will fire every time test.alltests view will get rendered so make sure if it is actually rendering. Third thing, you would most likely want to do something like this:

//controller
public function show($code){
    return View::make('test.alltests')->with(compact('code'));
}

//somewhere in the app, most likely in service provider
View::composer('test.alltests', function($view){
    $thepatient = Patient::where('document', '=', $view->code)->first();
    Log::info("In the patient composser");
    $view->with('patient', $thepatient);
});

Let us know if you have any more questions.

0

Hi, i'm didn't get your suggestion, i placed the View::composer code inside app/config/app.php

The result was the same.

Thanks.

0

I did not say you should put it in app/config. I said you should most likely put it in service provider. You can learn about service providers from documentation. Or you can place it wherever else you want, just not config files for god sake ;] For example you can use app/filters.php

0

Thanks for help zaalbarxx

The thing is:

I have a method in the controller that get the patient from database, and use it for a detail patient view. In that method i want to make the patient data available to the test:

public function patientDetail($code){
    // Obtain the patient
    $thepatient = Patient::where('document', '=', $code)->first();
    /**
     * Composer to mantain the patient data
     */
    View::composer('test.alltests', function($view){
        Log::info("In the patient composser");
        $view->with('patient', $thepatient);
    });
    return View::make('patient.detail', compact('thepatient'));
}

So, later i make the test.alltests return view in another method in the same controller, so, do i need to make anything else?

Last updated 9 years ago.
0

You $thePatients isn't in the scope of the callback. You need to use the "use" statement like so:

public function patientDetail($code){
// Obtain the patient
$thepatient = Patient::where('document', '=', $code)->first();
/**
 * Composer to mantain the patient data
 */
View::composer('test.alltests', function($view) use ($thepatient) {
    Log::info("In the patient composser");
    $view->with('patient', $thepatient);
});
return View::make('patient.detail', compact('thepatient'));

}

0

Hi Garbee, thanks for help

The composer code inside doesn't execute, i can't see the message.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

jpilldev jpilldev Joined 28 Aug 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.

© 2024 Laravel.io - All rights reserved.