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
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,
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.
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,
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community