Answer the question
In order to leave comments, you need to log in
Why is flash data not saved?
The problem is that when saving (the controller's store method), the message is saved to the session ( flash()->success('Location saved') ), but after redirecting to the index method, this message is no longer there. The same thing happens if you save data in flash.
There are no superfluous redirects, I checked it by writing to the log every time I contacted the service provider, there were two entries in the log (the first - saving, the second - after the redirect).
Routes:
Route::group([
'prefix' => config('chunker.admin.prefix', 'admin'),
'namespace' => 'Admin',
'middleware' => ['admin']
], function () {
$dir = __DIR__ . '/routes/admin';
$files = array_slice(scandir($dir), 2);
foreach ($files as $file) {
require_once $dir . '/' . $file;
}
});
// Роут находящийся в routes/admin
Route::group([
'prefix' => 'places'
], function () {
Route::get('list', [
'uses' => '[email protected]',
'as' => 'admin.places',
]);
Route::put('store', [
'uses' => '[email protected]',
'as' => 'admin.places-store',
]);
});
function index() {
$this->authorize('places.view');
$places = Place::get();
return view('admin.places', compact('places'));
}
function store(Request $request) {
$this->authorize('places.edit');
$data =$request->all();
$data['latitude'] = (float)str_replace(',', '.', $data['latitude']);
$data['longitude'] = (float)str_replace(',', '.', $data['longitude']);
Place::create($data);
flash()->success('Место сохранено');
return redirect()->route('admin.places')->with('test', '123');
}
@php( dd( session()->all() ) )
Answer the question
In order to leave comments, you need to log in
What's the problem with doing this?
And on the page:
@if($success = session('success'))
{{ $success }}
@endif
You also need to add middleware - web:
Route::group([
'prefix' => config('chunker.admin.prefix', 'admin'),
'namespace' => 'Admin',
'middleware' => ['web', 'admin'] // Вот тут
], function () {
$dir = __DIR__ . '/routes/admin';
$files = array_slice(scandir($dir), 2);
foreach ($files as $file) {
require_once $dir . '/' . $file;
}
});
For those who are interested, I found a solution. More precisely, inattention and inexperience with laravel. It turns out that the web intermediary was hung twice on this route and similar routes, and during processing, the session was recreated, so the response was already a new, clean session in which there was no data.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question