Reputation: 1875
I'm trying to implement in my controller a return redirect to an external URL using Laravel's
redirect->away('external URL')
.
But in my case, I want to add a flash message.
Here's what I tried:
dashboard.blade.php
return redirect()->away('$externalDomain')
->with('msg','Redirected!');
Expected Output:
I want the message to appear in the dashboard after the external redirect, but it does not, only after refreshing the page.
Upvotes: 1
Views: 785
Reputation: 384
If you're using Laravel 5.8, session in blade is a helper function as per the docs here:
https://laravel.com/docs/5.8/responses#redirecting-with-flashed-session-data
In your controller
Route::post('user/profile', function () {
// Update the user's profile...
return redirect('dashboard')->with('status', 'Profile updated!');
});
So use the helper function in blade like this:
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
NOTE:This will only work if you are using a page submit. If it's a javascript submit you may need to refresh the page to get the alert to show up
Upvotes: 0
Reputation: 33186
You can't.
A session is something that runs locally on your server and another website cannot access this. If it would be able to do so, this would be an immense security risk.
What you can do is add a query parameter to the URL you are sending the user to and add the information there. It all depends on what the external website is.
Upvotes: 1