I did this command
php artisan make:controller BrandController
I added thefollowing line of code in the routes.php file
Route::resource('admin/brands', 'BrandController');
All the methods in the controller get fired except for the index()
I checked the routes list and it is there
URI Name Action
admin/brands admin.brands.index App\Http\Controllers\BrandController#index
I have no idea and have looked and looked and looked but cannot figure it out. Any help would be greatly appreciated
I had also added the Route
Route::resource('admin', 'ProductController');
when it should have been
Route::resource('admin/products', 'ProductController');
Took me over an hour to spot it. I am going to get some sleep
Related
i wrote url like that
use App\Http\Controllers\DashController;
Route::get('/admin/special', [DashController::class, 'addSpecializations'])->name('add.sp');
this is controller
public function addSpecializations()
{
return view('dashboard.add-specializations');
}
when i tried to open it i can't even though all route work
after that i wrote this code in view's file
<a href="{{route('add.sp')}}">
so i faced this issue
Route [add.sp] not defined.
In case your routes are cached, run php artisan route:clear. In development, don't cache anything, including views and config.
I have had some weird issues in the past with Laravel routing, however they could usually be fixed with some form of logical solution, eg. clearing the route cache, or a genuine user error...
But this one is very strange. I have been developing this site for a few weeks and using the /admin routes for some time, but today anything related to /admin or logging in is resulting in a 404 | not found from Laravel. And now even adding any new routes is not working, including very basic ones.
eg. the home page is routed like this:
Route::get('/', [App\Http\Controllers\FrontendController::class, 'home'])->name('home');
But adding:
Route::get('/test', [App\Http\Controllers\FrontendController::class, 'home'])->name('test');
To my web.php routes is also bringing me to a 404.
Just to explain my development environment, I am on Windows and I have tried serving this with both "php artisan serve", and also with XAMPP, but both are giving me the same issue. I won't bother explaining the XAMPP set up, because this was literally working yesterday and nothing has changed, but with php artisan serve it takes me to "http://127.0.0.1:8000/".. this doesn't require any special hacking.. it usually just works.
What have I done differently today?
So all I have done today is:
Added a new command with "php artisan make:command SomeCommandIStartedMaking"
This surely hasn't screwed anything up? I've even deleted the command and reset to my last commit just in case and still the routes are screwed.
In my windows "hosts" file I added "127.0.0.1 somedomain.com"
So this sounds like the kind of thing that would have an effect on routing, and it's where I first noticed the issue.. but since then I have "ipconfig /flushdns", I have removed the entries from my host file, and I have cleared my laravel routes and caches, but still the issue remains.
I am really stuck on this one. Also finally! I have done a route:list and I can clearly see the routes showing up like expected, but I can assure you that nothing has changed since yesterday so this seems like another issue.
Here is a dump of web.php, because I know this will be asked for:
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
// Frontend
Route::get('/', [App\Http\Controllers\FrontendController::class, 'home'])->name('home');
Route::get('/instagram-gallery', [App\Http\Controllers\FrontendController::class, 'instagramGallery'])->name('instagram-gallery');
Route::get('/{pageAlias}', [App\Http\Controllers\PageController::class, 'index'])->name('page');
Route::post('/contact-send', [App\Http\Controllers\PageController::class, 'contactSend'])->name('contact-send');
Route::get('/test', [App\Http\Controllers\FrontendController::class, 'home'])->name('test');
// Admin
Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'is_admin']], function(){
Route::get('/', [App\Http\Controllers\AdminController::class, 'index'])->name('admin');
Route::get('/search/{table}', [App\Http\Controllers\AdminController::class, 'search'])->name("admin-search");
Route::get('/browse/{table}', [App\Http\Controllers\AdminController::class, 'browse'])->name("admin-browse");
Route::get('/create/{table}', [App\Http\Controllers\AdminController::class, 'create'])->name("admin-create");
Route::get('/edit/{table}/{id}', [App\Http\Controllers\AdminController::class, 'edit'])->name("admin-edit");
Route::get('/manage-account', [App\Http\Controllers\AdminController::class, 'manageAccount'])->name("admin-manage-account");
Route::get('/documentation/{subject?}', [App\Http\Controllers\AdminController::class, 'documentation'])->name("admin-documentation");
Route::post('/create/{table}/action', [App\Http\Controllers\AdminController::class, 'createAction'])->name("admin-create-action");
Route::post('/edit/{table}/{id}/action',[App\Http\Controllers\AdminController::class, 'editAction'])->name("admin-edit-action");
Route::post('/delete', [App\Http\Controllers\AdminController::class, 'deleteAction'])->name("admin-delete-action");
Route::post('/wysiwyg-upload', [App\Http\Controllers\AdminController::class, 'wysiwygUpload'])->name("wysiwyg-upload");
Route::post('/manage-account-action', [App\Http\Controllers\AdminController::class, 'manageAccountAction'])->name("admin-manage-account-action");
});
require __DIR__.'/auth.php';
One thing to add, is that "/contact" resolves just fine which is using the '/{pageAlias}' route as shown above, so some are working and some aren't. How should I trouble shoot this I don't even know where to start :(
Any help would be hot! This is so frustrating haha! Thanks in advance..
This might due to cache so run following commands
php aritsan config:clear
php artisan route:clear
To use single command:
PHP artisan optimize
The problem is the order of your routes - the code will run line by line trying to find a matching route.
Once it hits
Route::get('/{pageAlias}', [App\Http\Controllers\PageController::class, 'index'])->name('page');
It will match /test and naturally stop - never reaching your next route.
To solve this, your specific route /test needs to be defined before your general "catch-all" route /{pageAlias}
I am developing an application using Laravel 8.x. I have an api.php file that I am using. It was all working fine for the last 5 months. Today I added a new route to the api.php file and that route is not getting picked up by the Laravel. I have the following items in the api.php file
//Products
Route::get('/products/{currency_id?}/{type?}/{eventtype?}', [Controllers\ProductsController::class, 'getproduct2']);
Route::get('/products/search/{query}/{itemtype?}/{itemcategory?}', [Controllers\ProductsController::class, 'findproduct']); //getproduct
Route::post('/products/findproductbyid/{product_id}', [Controllers\ProductsController::class, 'getproduct']);
Route::post('/products/create', [Controllers\ProductsController::class, 'setproduct']);
Route::post('/products/update', [Controllers\ProductsController::class, 'putproduct']);
And it shows up the URL list also
but when I access it (findproductbyid) in the browser it is not getting picked up. it shows the results of /products/{currency_id}/{type}/{eventtype}
Please tell me to know why is it so? I tried clearing Laravel cache, etc.
Thanks in advance
UPDATE: I tried changing the GET to POST, but it seems it is not getting updated to POST
You don't define url parameters with $, here you done {$product_id}
Change it to the following.
Route::get('/products/findbyproductid/{product_id}', [...]);
Rearrange the routes like this and try it out
Route::post('/products/findproductbyid/{product_id}', [Controllers\ProductsController::class, 'getproduct']);
Route::get('/products/search/{query}/{itemtype?}/{itemcategory?}', [Controllers\ProductsController::class, 'findproduct']); //getproduct
Route::get('/products/{currency_id?}/{type?}/{eventtype?}', [Controllers\ProductsController::class, 'getproduct2']);
I am using Laravel 5.0 and been developing on this project for months without any problems. I just added a new route with a new method in the controller. But whatever I do, all these new entries in the routes.php file show me a blank page.
In my routes.php:
Route::get('dashboard/product_categories/testing', 'ProductCategoriesController#testing');
In the ProductCategoriesController.php:
public function testing() {
die('Hello world!');
}
This happens to all new entries in the routes.php. No matter what controller its pointed to.
I do not use route:cache so am clueless where this problem stems from
Please note: This is an unchanged project. The httpd server is running as it should and the storage folders have read/write permissions
If you have a resource controller for the dashboard try to add the new routes before the resource.
I totally forgot about this question, but I found the solution: php artisan route:clear
For me, none of the answers helped.
My problem was with two routes matching each other.
A sample of my web.php file is below:
Route::get('user/{user}', 'UserController#show');
Route::get('user/restore, 'UserController#restore');
It took me a while to realise what was happening here.
Despite the fact that $user was typecast in my controller to an instance of User; I just assumed that the string restore would not match that route.
In the end, I realised that the string restore was being passed as a parameter to the route above and was, therefore, failing to match a User model.
To solve this I had to change the route to the following:
Route::get('user/{user}', 'UserController#show')->where('user', '\d+');
Route::get('user/restore, 'UserController#restore');
Now only numbers are matched to that route and the restore route works as expected.
The other solution would be to change the order but I didn't want to do that.
Try clearing the cache:
php artisan cache:clear
Try deleting this before public function methods :
#return \Illuminate\Http\Response
Is there any possibility to turn on and turn off Laravel 5 maintenance without php artisan up and down commands when my website is being hosted ?
What I've done:
Route::get('site/shutdown', function(){
return Artisan::call('down');
});
Route::get('site/live', function(){
return Artisan::call('up');
});
The first route is working fine. But when I call site/live the site still is shuted down. What can cause this problem ?
If your project is already down, you cannot call another function.
What happens after you run php artisan down is that it creates a file named down inside storage/framework. After running php artisan up the file is removed.
You can create the file manually inside storage/framework. It will down your project. When you want to take your project live again, just remove the file.
I think the right answer is missing here..
You could add your route to app/http/middleware/CheckForMaintenanceMode.php
protected $except = [
//here
];
So It never would be off.
when you run artisan down. site is not available so when try to call up, your IP can't access site.
you must call down with your IP exception.
php artisan down --allow=127.0.0.1 --allow=192.168.0.0/16
or add ::1 to local.
to make that in route without command
try to save this command in specific one and call it.
Laravel 8 introduced secret in maintenance mode, in which you can bypass the maintenance mode by providing a secret, then your Artisan::call would work.
You could add your routes to the $except var in CheckForMaintenanceMode middleware to bypass the check. Then your site/live route would work just fine.
In order to make your site live again using an url, you can create a live.php file which you put in laravel's public folder and then visit http://your.domain/live.php .
In the live.php file you need something like this: (check your projects directory structure if you don't use the default public folder!)
<?php
unlink(dirname(__FILE__) . "/../storage/framework/down");
header("Location: your.domain");
die;
just put
Artisan::call('up');
without route function.