laravel-livewire return view on button click - laravel

I have one button in livewire view
<x-jet-button wire:click.prevent="confirmProcess" class="bg-blue-500 hover:bg-blue-700">
Next
</x-jet-button>
and here in controller my method
public function confirmProcess()
{
return view('livewire.confirm');
}
I also have view in livewire folder with name confirm.blade.php
I want to load different view on button click but when I click on button nothing happens.
how can I load other view also I want to use data from same controller also on other view.
Thanks

You can't return view from your confirmProcess method. What you can do is redirect from confirmProcess method to a named route like:
return redirect()->route('confirm');
Then from this route you can call the component like:
Route::get('/confirm-process', \App\Http\Livewire\Confirm::class)->name('confirm');

Related

Call controller function from button inside view?

I want to call a controller function when i click a button but the problem is when i enter the page where the button is the function that im testing runs without clicking the button and i dont know why.
Here is my button.
<button href="{{action('PlantillaImagenesController#testboi')}}" style="width:27%" class="p-2 btn btn-primary btn-lg">Guardar</button>
The function that im testing.
public function testboi(){
echo "Funcion controller";
}
My route.
Route::get('/Imagen', 'PlantillaImagenesController#testboi');
Make this change to your button:
Guardar
your button URL should match with the route name,
this is how you call a route in laravel.
You can also name your route like this:
Route::get('imagen', 'PlantillaImagenesController#testboi')->name('imagen');
And use it like this:
Guardar

Laravel : how to execute controller function on button in view?

I want to call controller function in view page.
Here is function code :
public function annulerSeanceConduite(Request $request,SeanceConduite $seanceConduite)
{
//
$seanceConduite->statut = "Annulée";
$seanceConduite->save();
$request->session()->flash('message', 'Seance Conduite est annulée!');
return redirect('seanceConduites');
}
And the route :
Route::get('annulerSeanceConduite', 'SeanceConduiteController#annulerSeanceConduite');
You can assign name to your Route when you define it and use that name to generate the correct URL in your view file
Route::get('/annulerSeance/{id}', 'SeanceConduiteController#annulerSeanceConduite')
->name('annulerSeance');
and in your view file you use it like this
Annuler
Instead of a button, you could use a normal "a", or bind the link the the specified route to an onclick event on the button.

ajax method return view code instead redirect on view in laravel

I have many buttons in single form that's why i used ajax to call different method on different button click event. But while I call method using ajax and return view, it send code of view as response, And i need to redirect on that view my method code is as below.
public function store(Request $request)
{
return view('surat.proceed_sell');
}
can i redirect on other view using ajax? Or any other way to call different methods on different button click event then please let me know.
What you could do is return the url where to redirect as a response in your controller as
return url('the path');
and in your ajax success callback you could redirect to the view as
window.location = data;
The url should be defined in your route file where the view is rendered.
You cannot redirect to a view with Ajax because Ajax expects a response. What you should do is redirect to a page instead, using anchors.
First, define your routes
Route::get('surat/proceed', 'SuratController#proceed');
Then use anchor with a button to go that page. It doesn't matter how many buttons you have in the form, as longs as they are not of type submit, they should not submit the form.
<form method="post" action="">
Go to proceed
<button type="submit" class="btn btn-primary">Submit</button>
</form>
If this does not help you, please, update your question with your form code.

Passing name of button on click to controller in web2py

Basically what i want is that in my view file i have a list of various restaurants,and in front of each of them is a "show" button,which on clicking should display three more buttons(dynamically),where each button performs some action regarding the corresponding restaurant name(like show menu,show reviews)(this action should be dynamic too). Can anybody help me with this implementation.
In the view you can place a link and a target container:
{{=A('the link', callback=URL('controller', 'function', args=[my_arg]), target="callback-target", _class="btn btn-default")}}
<div id="callback-target"></div>
If the link is clicked the function in controller is called and you can read the argument my_arg with:
def function():
data = request.args(0)
response.flash('Data received!')
return DIV('Return anything ...')
The returned data is displayed in <div id="callback-target"></div>

Passing parameter to same page with CodeIgniter

I have a controller that loads a page view. The page is actually a template of sorts; when a user clicks a button, content is loaded into a div based on the parameters passed through the button link. All button URLs go to the same page, it just passes a parameter. So for example, I have a page controller and a page_view file. When I click on the login button I want to go to the same page, but just pass action="login". If I clicked on "see stats", then I would want to pass action="stats".
Without Codeigniter I know I can just set the URLs on the buttons to "?action=stats" or "thisurl?action=stats", and within the page itself I have code that checks to see what the value of action is, and then generated content based on value.
How can I do this with the CodeIgniter framework?
You can call methods on a controller. So if you call a page like /your_controller/login, then it will call the login method in the controller and you can change the view to match that:
class Main extends CI_Controller {
function Main(){
parent::__construct();
// called when /main is accessed
// load your main view here
}
function login(){
// called when /main/login is accessed
// tweak view to match login view
}
}
More info here: http://codeigniter.com/user_guide/general/urls.html

Resources