How Can I Remove “public/index.php” in the Laravel Url generated? [duplicate]

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

Laravel 4 : Route to localhost/controller/action

If you are looking for a more automated routing, this would be the Laravel 4 way: Route: Route::controller(‘users’, ‘UsersController’); Controller (in this case UsersController.php): public function getIndex() { // routed from GET request to /users } public function getProfile() { // routed from GET request to /users/profile } public function postProfile() { // routed from … Read more

Laravel error: Missing required parameters for route

You have to pass the route parameters to the route method, for example: <li><a href=”https://stackoverflow.com/questions/35259948/{{ route(“user.profile’, $nickname) }}”>Profile</a></li> <li><a href=”https://stackoverflow.com/questions/35259948/{{ route(“user.settings’, $nickname) }}”>Settings</a></li> It’s because, both routes have a {nickname} in the route declaration. I’ve used $nickname for example but make sure you change the $nickname to appropriate value/variable, for example, it could be something … Read more

Laravel says “Route not defined”

The route() method, which is called when you do [‘route’ => ‘someroute’] in a form opening, wants what’s called a named route. You give a route a name like this: Route::patch(‘/preferences/{id}’,[ ‘as’ => ‘user.preferences.update’, ‘uses’ => ‘UserController@update’ ]); That is, you make the second argument of the route into an array, where you specify both … Read more

Error “Target class controller does not exist” when using 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

Laravel Controller Subfolder routing

For Laravel 5.3 above: php artisan make:controller test/TestController This will create the test folder if it does not exist, then creates TestController inside. TestController will look like this: <?php namespace App\Http\Controllers\test; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class TestController extends Controller { public function getTest() { return “Yes”; } } You can then register your route this … Read more

Laravel Route issues with Route order in web.php

When accessing a route, Laravel goes through your list of routes top to bottom, until it finds one that ‘matches’ at which point this route is immediately selected. In your example, when trying to access /blog/bin using GET, it has two potential matches: Route::get(‘/blog/{id}’, ‘BlogController@show’); and Route::get(‘/blog/bin’, ‘BlogController@bin’); In this case, Route::get(‘/blog/{id}’, ‘BlogController@show’); comes first … Read more

Access query string values from Laravel

For future visitors, I use the approach below for > 5.0. It utilizes Laravel’s Request class and can help keep the business logic out of your routes and controller. Example URL admin.website.com/get-grid-value?object=Foo&value=Bar Routes.php Route::get(‘get-grid-value’, ‘YourController@getGridValue’); YourController.php /** * $request is an array of data */ public function getGridValue(Request $request) { // returns “Foo” $object = … Read more