This is what I settled for:
I pass the documents id through to the modal:
@click="$modal.show('showDocument', {document: '{{($document->id)}}'})"
In my controllers show method, I have this:
public function show(Document $document)
{
return response()->json([
'document' => $document,
], 200);
}
In my Vue view, the axios get request is simply hitting the show method:
getDocument: function (document) {
axios.get('documents'/ + document).then((response) => {
this.document = response.data.document;
}).catch(error => {
console.log(error);
})
},
To ensure that this specific show method can only be accessed from an AJAX request, I have created a custom middleware:
RequestIsAjax.php:
public function handle($request, Closure $next)
{
if (! $request->ajax())
return abort(403);
return $next($request);
}
And applied it to my controller, like so:
$this->middleware('ajax', ['only' => ['show']]);
Above seems to be working. However, I am still unsure if this is the most optimal way to go about this? Any input would be appreciated!