cyno - 1 week ago

Hi, How can I return a view to display after ajax form request? Do I use $builder->on(), or something else? FormHandler at the moment:

class ProductFormHandler {

use DispatchesJobs;

public function filter(FormBuilder $builder, ProductRepositoryInterface $products)
{
    $product = $products->findByFilters($builder->getFormValues()->all())->first();
    $view = view('myview', compact('product'))->render();

    $builder->on(
        'json_response',
        function (Collection $data) use ($view) {
            $data->put('test', $view);
        }
    );
}

}

finnito - 1 week ago

Hey @cyno!

Could you show what your getting as a reponse at the moment or what errors you are encountering?

You are correct in using view()->render() to get the HTML for the view, so that’s great. There is this response on SO which covers a similar problem, so that might be of help.

https://stackoverflow.com/a/28635193

cyno - 1 week ago

Thank you for your answer @finnito! I've seen this SO response, if i do this its just returns nothing, the response is blank. If i use Collection in the callback everything is fine, without the view, but with view included, it just give blank return as well. Also if i dd() the view instance its fine, but if i call render() its just blank again. I dont see errors in any of the cases.

cyno - 1 week ago

Maybe the problem is that i use blocks in the rendered view? I can provide some code in an hour.

finnito - 1 week ago

Okay sounds great! It’s late here so I can check your code when I wake in the morning and do some testing myself if you can’t figure it out!