check for successul elequent query i do not know why if conditional always yields an error
public function step2(Request $request)
{
$invoice_id = session('invoice_id');
$invoiceWithItems = Invoice::with('items')->find($invoice_id);
if($invoiceWithItems){
return view('components.pages.guest.step2page', ['invoiceWithItems' => $invoiceWithItems]);
}
back()->with('top','Incorrect invoice data');
}
Undefined variable $invoiceWithItems (View: /resources/views/components/pages/guest/step2page.blade.php)
when I pass the $invoiceWithItems to the view, it is undefined, whereas when returning it directly as JSON .. it works
Do I have to check for a successful query? and what is the proper way to do that?
It seems like you are checking correctly. But make sure you don't have any other place from where you are returning that view and you forgot to pass the invoiceWithItems.
@lifesound you should have a blade view returned, like for example:
<x-app>
<x-pages.guest.step2page :invoices="$invoiceWithItems" />
</x-app>
in your component:
@props('invoices')
// use $invoices here
and from the controller just return the blade view, not the component.
Show how you are actually returning the view and passing data to the view, e.g.
return view('components.pages.guest.step2page', compact('invoiceWithItems'));
or
<x-pages.guest.step2page :invoiceWithItems="$invoiceWithItems" />
EDIT this is a Blade component??? How are you actually using the step2Page???
@lifesound is this a Blade component, or is it a regular Blade template?
@lifesound so you have <x-pages.guest.step2page /> somewhere in another template?
Your anonymous Blade component can accept data using data properties . You would not actually be returning the view directly!
<x-pages.guest.step2page :invoice-with-items="$invoiceWithItems" />
@tykus I changed it to the old-fashion
@extends('components.layout.guest')
@include('components.layout.stepper',['step'=> '2'])
@include('components.layout.step2', ['invoiceWithItems' =>$invoiceWithItems])
So why i have the same error ?
Undefined variable $invoiceWithItems (View: /resources/views/components/pages/guest/step2page.blade.php)```
@lifesound and where does $invoiceWithItems come from for this old-fashioned view?
@tykus from invoiceController
public function step2(Request $request)
{
$invoice_id = session('invoice_id');
$invoiceWithItems = Invoice::with('items')->find($invoice_id);
if($invoiceWithItems){
return view('components.pages.guest.step2page',compact('invoiceWithItems'));
}
back()->with('top','Incorrect invoice data');
}
@lifesound so, the view you are returning is the same Blade template as the Blade component/Blade template partial that you @include in that Blade template???
// step2page.blade
<x-layout.guest>
<x-layout.stepper :step="2"/>
<x-layout.step2 :invoiceWithItems="$invoiceWithItems"/>
</x-layout.guest>
@lifesound you should not return a component from your controller but a VIEW that contains those components.
@Nakov it worked for me because it is anonymous
@Nakov I have changed all the website to the old-fashion blade
and remove all the views from /components dir
and still have the same err
Please sign in or create an account to participate in this conversation.