Support the ongoing development of Laravel.io →
Views Blade Forms
Last updated 1 year ago.
0

So you want some kind of dialog, asking a yes / no question?

You could have your controller pass to the view an option to show the dialog or not...

// in controller
public function show()
{
    $showDialog = true;

    return view('show', ['willShow' => $showDialog]);
}
<!-- in blade -->
@if($willShow)
  <script>
    confirm('are you sure?');
  </script>
@endif
0

Thanks, Exactly. I need to ask the user yes / no question.

I know I can pass options to the view and in the to handle dialog. But base on the answer I need to return to my controller and continue with the logic. Also in my controller I need to read Input from the form and if I return to the view and go back to controller I loose Input.

thanks,

0

You will need to look up some Ajax information. Since you suggested Sweet Alert I assume you are using jQuery, so look up how to do some Ajax requests with jQuery.

Then you will just perform an Ajax request to your controller, you controller will handle the logic and return a response (like)

return response()->json([
  'status' => 'success',
  'data' => ['something' => 'else', 'you' => 'might need']
);

In your javascript you will have access to the data that gets passed back, thus your JavaScript (again) will need to figure out what to do next.... :)

Unless you just want to make different methods for what the user chooses and you just forward them on to that route/method.

0

thank you for reply.

I tried that it did work. However in my blade I have input with list of UploadedFiles, when in my controller I do return to blade back()->withInput(); to run dialog I loose values in UploadedFiles. After calling controller again of course my Input::file('import_file') is empty. Is there any wait to store info about uploadedfiles? I know i can't do it in session and I don't need to store physical files as I import data to DB.

thanks,

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Vannia vannia Joined 22 Aug 2016

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.