Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser Back Button Laravel

Tags:

php

laravel

So I have this back buttons I use this when I create a building then theres a back button for the homepage for edit also and its working.

The problem is I have an OfficePage which have create and edit also, the back button for office page is not working every time I click the create office when I press Back it doesnt refresh the page I have to refresh it so I can see the office that I created heres my routes and code for it.

This is the back button code for building

<a href="{{route('index')}}" class="btn btn-default btn-md"> GO Back</a>

This is the back button code for office

<a href="javascript:history.back()" class="btn btn-default">Back</a> 

Routes

Route::get('/home', 'HomeController@index')->name('home');

Route::get('/', 'BuildingController@index')->name('index');

Route::get('building/{id}', 'PageController@show');

Route::get('buildings/create', 'BuildingController@create')->name('createbform')

Route::post('building/create/store', 'BuildingController@store')->name('createbuilding');

Route::get('building/{id}/edit', 'BuildingController@edit');

Route::post('building/{id}/edit', 'BuildingController@update')->name('editbuilding');

Route::get('building/{id}/delete', 'BuildingController@destroy');

Route::get('office/{id}', 'OfficeController@show')->name('officeMenu');

Route::get('building/{id}/offices/create', 'OfficeController@create')->name('createofficeform');

Route::post('building/{id}/offices/create/store', 'OfficeController@store')->name('createoffice');

Route::get('building/{id}/offices/edit', 'OfficeController@edit')->name('editofficeform');

Route::post('building/{id}/offices/edit', 'OfficeController@update')->name('editoffice');

Route::get('offices/{id}/delete', 'OfficeController@destroy')->name('deleteoffice');
like image 381
TeamPlar Jarj Avatar asked Nov 26 '25 05:11

TeamPlar Jarj


2 Answers

Use url()->previous():

<a href="{{ url()->previous() }}" class="btn btn-default">Back</a> 

If you want to return 2 requests back, use this solution.

like image 138
Alexey Mezenin Avatar answered Nov 28 '25 20:11

Alexey Mezenin


When using the "history.back" function, the browser used to give you a copy from it's cache instead of reload the page. Best way here is not to use the "history.back" function but use the correct route to get a fresh copy of your page.

like image 44
Paladin Avatar answered Nov 28 '25 20:11

Paladin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!