Comments (13)
any solution for this issues ?
from laraflash.
I've found easiest solution for this LaraFlash on redirected route issue. No need to check the redirected request or action route or add keep() method or no need to make new Vue component.
Make changes in your code with below code. Hope it will solve the issue. But priority or any ordering things won't work. Thanks.
Add this below piece of code above the notification Vue object code written. And then pass this $session variable to notification Vue object data.
@php
$sessions = array();
$laraflashes = session()->get('laraflash');
if (!is_null($laraflashes)) {
$sessions = $laraflashes->toArray();
}
session()->forget('laraflash');
@endphp
data: {
session: {!!json_encode($sessions)!!},
validMethods: ['general', 'primary', 'success', 'info', 'warning', 'danger', 'snackbar']
},
from laraflash.
Yep. I need to document this feature. But this package uses the same core flash session underneath it as the basic laravel session management. So just like the normal flash sessions in Laravel, flashed data only lasts for 1 request. When you do a redirect within a controller you are actually creating another request which is why you have to use LaraFlash::keep()
in order to persist it for another request.
from laraflash.
Until @jacurtis or anybody address this issue, I propose the following - Using default Laravel flash message. In your method do it as usual with slightly different approach within the message itself:
return redirect()->back()->with('status', 'success|Your message');
Notice that the flash message contains the pipe "|" which basically "divides" the type of the notification and text.
To use this feature then you can create a VueJS component alternating the code @jacurtis provided for the frontend side. I registered the component as toasty-notification. Alternated part looks like this:
props: {
text: {
type: String,
default: null
}
},
data: function() {
return {
session: this.text,
validMethods: ['general', 'primary', 'success', 'info', 'warning', 'danger', 'snackbar']
}
},
mounted: function() {
let vm = this;
this.$nextTick(function() {
if ( vm.session !== '' )
{
let res = vm.session.split('|');
if (_.includes(vm.validMethods, res[0].toLowerCase())) {
vm[res[0].toLowerCase()](res[1]);
} else {
vm.general(res[1]);
}
}
})
},
// the rest of the methods.
And finally place this component in your blade view like this:
<toasty-notification text="{{ session('status') }}"></toasty-notification>
So this is the quick hack :)
from laraflash.
Common @jacurtis , please man!
Work on a fix for its issue! The @gorankrgovic hack is good, but need to be on every single blade view!
from laraflash.
Fix:
LaraFlash::keep();
from laraflash.
Sorry again, I only closed this issue because I saw your tweet resolving someone else's case.
I am trying to get this working with my implementation, but just can't!
LaraFlash::success('Successfully created a new profile! (' . $profile->name . ')')->keep();
return redirect(route('profile.show', $profile->link));
LaraFlash::success('Successfully created a new profile! (' . $profile->name . ')');
LaraFlash::keep();
return redirect(route('profile.show', $profile->link));
Both code samples above fail to persist the flash through two requests.
from laraflash.
Same problem here. LaraFlash::keep (); does not seem to do anything when dealing with redirections (unless I'm using it wrong). Has anyone managed to successfully use keep () with redieections? Please share how this can be implemented?
from laraflash.
is there any solution ::keep() didn't work for me.
from laraflash.
it only works if i did return view('') when i redirect nothing happens.
from laraflash.
+1
from laraflash.
I've found a pretty easy workaround. If you redirect to an action instead of a route you can place your LaraFlash object it the action code. Create a 'redirected' variable and include it in the request.
Code example for UserController
public function update(Request $request, $id)
{
return redirect()->action(
'UserController@show', ['id' => $id, 'redirected' => 'true']
);
}
public function show(Request $request, $id)
{
$user = User::findOrFail($id);
if($request->redirected) LaraFlash::new()->content('User Updated')->title('Success')->type('success');
return view('manage.users.show')->withUser($user);
}
from laraflash.
@shahnotes I didn't go deep into your solution, but it works! Thx!
Any ideas how to get it working with original functionality?
from laraflash.
Related Issues (12)
- Create Notification object for each flash notification HOT 1
- Additional Methods to Add
- Complete Readme
- Create publishable config file HOT 1
- Create methods to instantiate a Notification with Type HOT 1
- Fluent Interface for New Notifications HOT 1
- Update Contribution Guidelines for first major release
- LaraFlash Package HOT 1
- LaraFlash not working on laravel 5.5 HOT 1
- Installed Laraflash and getting error. HOT 2
- Laravel Blade
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laraflash.