error while passing variables in a controller

Asked

Viewed 20 times

-1

Good morning programmers , I have a problem passing two variables from one function to another, I think. Below follows the Code

class pdfController extends Controller
{
    public function index($id)
    {
        $service = $this->get_service_data($id);
        return view('services.pdf')->with('service',$service);
    }
    public function get_service_data($id)
    {
        $service = Service::find($id);
        $materials=$service->mats_por_servicos = DB::table('mats_por_servicos as mats_serv')
            ->join('materials as material','mats_serv.mat_id','=','material.id')
            ->where('serv_id',$id)
            ->get();

        return [$service,$materials];
    }
    public function pdf()
    {
        $pdf =\App::make('dompdf.wrapper');
        $pdf->loadHTML($this->convert_service_to_html());

    }
    public function convert_service_to_html($id)
    {
        $service = $this->get_service_data($id);
    }

}

error:

inserir a descrição da imagem aqui

  • 2

    You are passing an array to your view, but you are trying to access it as if it were an object. Its variable service in view will be [$service, $materials], then you probably need to do service[0] to access the object you want.

1 answer

0

Hello, we noticed that the error is being reported in your view when accessing the service->Designation, in this case in the view do a DD to analyze how this object is coming in the view:

Na View:

{{ dd($service) }}

So you can analyze the model and the object data.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.