John Davidson

php - Only some functions controller work with laravel messages

0 comments
Message:


I have this functions in my controller


All functions here is working, but the "message" part is not working


I want to show a notification (like in the screenshot below) to be displayed after the functions are executed


public function destroy($id)
{
$this->meoRepository->deleteDigestReport($id);
return response()->json(["message" => __('digestReport.delete.success')]);
}

public function sendTest($id){
$this->digestReportService->sendTest($id);
return redirect()->route('digest-report.show', $id)
->with(["message" => __('digestReport.send.test')]);
}

public function startStop($id){

$this->meoRepository->startStopMeo($id);

if (MeoState::NOT_SENDING_REPORT){
return redirect()->route('digest-report.index')
->with(["message" => __('digestReport.startStop.stopped')]);
} else {
return redirect()->route('digest-report.index')
->with(["message" => __('digestReport.startStop.started')]);
}
}

none of the 3 generates response messages, however all work fine, create and edit work fine, with their respective messages


my api.php


Route::get('/digest-report/send-test/{digest_report}', 'DigestReportController@sendTest')->name('digest-report.send-test');
Route::get('/digest-report/start-stop/{digest_report}', 'DigestReportController@startStop')->name('digest-report.start-stop');

my web.php


 Route::resource('digest-report', 'DigestReportController', ['middleware' => ['role:superadministrator|administrator|user']]);

example with store function, it works, I want to do this, this is for my store function in the same controller


public function store(MeoRequest $request)
{
$userId = Auth::id();
$this->meoRepository->saveDigestReport($request, $userId);
return redirect()->route('digest-report.index')
->with(["message" => __('digestReport.store.success')]);
}

and it works correctly



this is my index view, in the part of message notification content


@section('content')
@if(Session::has('message'))
<div class="row">
<div class="col-lg-12">
<div
class="alert alert-{!! Session::has('status') ? Session::get('status') : 'info' !!} alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
{!! Session::get('message') !!}
</div>
</div>
</div>
@endif


My Answer:
laravel messages are not displaying properly. Can you please provide more information on what specific issue you are facing with the laravel messages?

Rate this post

3 of 5 based on 9040 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us