I am looking to return a Javascript file when a customer goes to a specific URL on my Laravel development. I will run a check against a DB table before showing the Javascript file;
The javascript file will be the same no matter what URL is requested so I just need to return a JS file.
I just need to know how to return the Javascript file.
Try this:
Route::get('account/{id}/javascript.js', function ($id) {
if (/* the ID exists in the database */ === false) {
abort(403, 'Forbidden');
}
});
Did not test it, but it should abort the call if the ID is non-existent, and show the JS otherwise.
You need the check-the-database logic here of course.