samedi 13 juillet 2019

Issue with View render function

I’m new to laravel, though I have a fairly good understanding of its workings though I can’t seem to solve the following issue.

In my app I have a product view, which displays a form with s bunch of fields. One part of the of the view displays a table with variants relating to the product. Users can add new variants to the product but click on a button which displays a modal. Once completed the modal will save the new variant information via Ajax. Upon saving the data in the dB a json object is returned with a success message and HTML string of the newly created variant in a table row which gets appended to the variant table.

Everything is working well. The issue I’m having is that the return HTML string is being outputted with the blade statements and not being converted to its associated or passed values.

In my controller class


$variant = Variant::create(
    ‘barcode’ => ‘abc123’,
    ‘size’ => ‘SM’,
    ‘colour’ => ‘Red’,
    ‘qty’ => ‘125’);

$html = view(‘variantTableRow’)->with(‘variant’, $variant)->render();

Return response()->json([
     ’status’ => true,
     ‘html’, $html
]);

In variantTableRow file

<tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>

Output in the main view file

<tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
</tr>


Sorry for the long explanation, but as you can see the render function is not passing the data into the view. I have been scratching my head why it’s not working.

Thanks for your help in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire