Laravel: How to Get Current Route Name? (v5 … v7)

Try this Route::getCurrentRoute()->getPath(); or \Request::route()->getName() from v5.1 use Illuminate\Support\Facades\Route; $currentPath= Route::getFacadeRoot()->current()->uri(); Laravel v5.2 Route::currentRouteName(); //use Illuminate\Support\Facades\Route; Or if you need the action name Route::getCurrentRoute()->getActionName(); Laravel 5.2 route documentation Retrieving The Request URI The path method returns the request’s URI. So, if the incoming request is targeted at http://example.com/foo/bar, the path method will return foo/bar: $uri … Read more

Download files in laravel using Response::download

Try this. public function getDownload() { //PDF file is stored under project/public/download/info.pdf $file= public_path(). “/download/info.pdf”; $headers = array( ‘Content-Type: application/pdf’, ); return Response::download($file, ‘filename.pdf’, $headers); } “./download/info.pdf”will not work as you have to give full physical path. Update 20/05/2016 Laravel 5, 5.1, 5.2 or 5.* users can use the following method instead of Response facade. … Read more

Laravel 5 – redirect to HTTPS

You can make it works with a Middleware class. Let me give you an idea. namespace MyApp\Http\Middleware; use Closure; use Illuminate\Support\Facades\App; class HttpsProtocol { public function handle($request, Closure $next) { if (!$request->secure() && App::environment() === ‘production’) { return redirect()->secure($request->getRequestUri()); } return $next($request); } } Then, apply this middleware to every request adding setting the rule … Read more

How Can I Remove “public/index.php” in the URL Generated Laravel?

Option 1: Use .htaccess If it isn’t already there, create an .htaccess file in the Laravel root directory. Create a .htaccess file your Laravel root directory if it does not exists already. (Normally it is under your public_html folder) Edit the .htaccess file so that it contains the following code: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule … Read more

Target class controller does not exist – Laravel 8

You are using Laravel 8. In a fresh install of Laravel 8, there is no namespace prefix being applied to your route groups that your routes are loaded into. “In previous releases of Laravel, the RouteServiceProvider contained a $namespace property. This property’s value would automatically be prefixed onto controller route definitions and calls to the … Read more