Reputation: 41
I want to call Laravel redirect from controller per documentation
https://laravel.com/docs/5.6/redirects#redirecting-controller-actions
but I get this error:
InvalidArgumentException Route [/gosterge_paneli] not defined.
here is how my codes look like
layout.blade.php
$("#myRedirectButton").click(function(){
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
method: 'post',
dataType: 'text',
url: 'redirect-testing-link',
success: function (data)
{
}
});
});
web.php
Route::post('/redirect-testing-link', function () {
return redirect()->route('/gosterge_paneli');
});
Upvotes: 0
Views: 435
Reputation: 2610
You are doing it wrong! change your action code
for 1
from
return redirect()->route({{ url('/gosterge_paneli') }});
to
Route::post('/gosterge_paneli', function(){
//do something
})->name('gost');
return redirect()->route('gost'); //your named route
for 3
from
return redirect()->action('/gosterge_paneli');
to
return redirect()->action('Controller@acton'); //the corresponding controller and method for `gosterge_paneli`
Redirect the URL through AJAX
Firstly return the url in response
return response()->json([url => route('name')]);
Then ajax success
success: function(response){
window.location.href = response.url
}
Upvotes: 2