Skip to content

Back URL, modals and options

The LteRequestOptions middleware (installation) keeps a little navigation state in the session.

On every GET request of a route named *.index (that is not an AJAX/JSON request) the middleware stores the full URL — with filters, sorting and page — in the session under the route name. Lte3::backUrl() reads it back:

<a href="{{ Lte3::backUrl('admin.posts.index') ?: route('admin.posts.index') }}">Back to posts</a>
return redirect()->to(Lte3::backUrl('admin.posts.index') ?: route('admin.posts.index'))->with('success', 'Saved');

backUrl($key) returns the first non-empty of:

  1. the _back parameter of the current request
  2. _back stored in the session — any GET request with ?_back=<url> stores it
  3. the session value under $key (the remembered index URL)
  4. ''

So a link can override where “back” leads: route('admin.posts.edit', [$post, '_back' => url()->full()]).

To remember other routes, extend the middleware and change $indexPageRouteNamesForBackAction (patterns for Str::is()):

class AdminRequestOptions extends \Fomvasss\Lte3\Http\Middleware\LteRequestOptions
{
protected $indexPageRouteNamesForBackAction = ['*.index', 'admin.reports.*'];
}

If a request has the _destination parameter (name: view.next_destination_key), the middleware stores its value in the session under the same key. The hidden action form of the layout sends the current URL as _destination, so links and buttons that submit through it (Actions and AJAX) tell the controller where the user was:

public function destroy(Post $post)
{
$post->delete();
return redirect()->to(session('_destination') ?: route('admin.posts.index'));
}

The package does not redirect by itself — reading the value is up to the controller.

If a request has the _modal parameter (name: view.modal_key), the middleware flashes it to the session, and the layout opens that modal on the next page: $('<value>').modal(). The value is a jQuery selector of a modal present on the page, e.g. one pushed to the modals stack.

{!! Lte3::formOpen(['action' => route('admin.orders.comment', $order)]) !!}
{!! Lte3::hidden('_modal', '#modal-comments') !!}
...
{!! Lte3::formClose() !!}

After the redirect back (also after a failed validation — old('_modal') is checked too) the page opens #modal-comments again. A link can do the same: route('admin.orders.show', [$order, '_modal' => '#modal-comments']).

The middleware stores per_page from the query in the session and sets it to 16 when the session has none. Read it in index actions:

$posts = Post::latest()->paginate(session('per_page'));

A link or a select with ?per_page=50 changes it for all following pages.

A GET request with one of the keys below switches its value in the session between two states and redirects to the same URL without the key:

KeyStates (first is the default)
lte_sidebar_collapse0, 1
product_group_collapsein, on
show_products_type_list0, 1

The package views do not read them; they are a mechanism for project views, e.g. session('lte_sidebar_collapse') ? 'sidebar-collapse' : '' on <body> of a published layout and a link ?lte_sidebar_collapse=1. To use your own keys or defaults, extend the middleware and override $toggleKeysValues and $enabledOptionKeys; beforeHandle() and afterHandle() are empty hooks for the same purpose.