I am getting an error message when trying to register all the controller routes in Laravel 4 (Illuminate) by adding:
Route::controller(Controller::detect());
to my routes.php
The error :
Error: Call to undefined method Illuminate\Routing\Controllers\Controller::detect() in C:\wamp\www\travless\app\routes.php line 13
I suppose they changed the function name, but I don't know where to find it because it is still an alpha version and there is no documentation I'm aware of.
This function has been removed in Laravel 4 because of inconsistent behavior with varying filesystems. The proper way to register controllers should be to explicitly define each one you wish to use in your routes file.
You need to register each controller manualy in routes.php file
Route::controller('users', 'UsersController');
First params stands for URL to respond, second one is controller's class name
Related
I used 2 routes for calling sam function
Route::get('/sami', 'App\Http\Controller\CommentController#sam');
Route::get('sami',[CommentController::class, 'sam']);
but still got this error -
"Illuminate\Contracts\Container\BindingResolutionException
Target class [App\Http\Controller\CommentController] does not exist."
did u put :
use App\Http\Controller\CommentController ;
you need to add it in the route
Laravel version has updated and the routes is now expecting an object instead of an id from when i last used it.
My Routes:
When I try to pass over the $item object which the method in the controller wants. I get a 404 not found and my logs aren't returning... meaning the function isn't running. When the $item obj is not passed over the function realizes that a parameter is missing thus the method is recognized by the blade as being the same as the one in the controller.
Calling the edit function in Blade:
Controller Code:
I appreciate any help whatsoever.
The order of your routes is probably wrong
when you first define the show route with /item/{item} and then create with /item/create laravel will think the "create" is the id (or reference)
best way is to have
the index
create
....
show
Code Example correct
Route::get('/', ProductIndex::class)->name('product.index');
Route::get('/new', ProductCreate::class)->name('product.create');
Route::get('/{product}', ProductShow::class)->name('product.show');
Code Example wrong
Route::get('/', ProductIndex::class)->name('product.index');
Route::get('/{product}', ProductShow::class)->name('product.show');
Route::get('/new', ProductCreate::class)->name('product.create');
I am using Laravel 5.5 version. I defined my routes in the routes.php file. like this:-
$router->group(['middleware' => 'auth'], function($router) {
$router->resource('/route-name', 'myController#myMethodName');
});
But when I run my application laravel gives error:-
Method [myMethodName#index] does not exist on [App\Http\Controllers\myController].
It is by default put index action after my defined action in the routes.
It is working fine in the laravel 5.3 version. Please solve my problem..
Try this as #devk told in comment:
$router->get('/route-name', 'myController#myMethodName');
By Default resource Request create CRUD requests in routes. For the following methods in Controller.
Index(GET)
Create(GET)
Store(POST)
Show(GET)
edit(GET)
Update(PUT/PATCH)
Delete(DELETE)
You can't pass method name in resource route.
If you want to override any of them. you have to write new one route below the resource Route. Like
Route::get('url','Controller#newMethod');
And Change the method name in Controller with newMethod
For more detail check laravel documents
I use vue.js and Laravel 5.1 to create a little file sharing application.
Everything works perfect but now I wanted to make sure the owner of each file is able to remove users from his file (he had to share the file with those users at first of course), therefore I make a PUT request to an URL called /files/share.
My Laravel route looks like this:
Route::put('/files/share', 'FileController#test');
When I run php artisan route:list it gets listed as well.
The client-side code looks like this:
this.$http.put('/files/share', { some_data }, function(data) {
if(data.error){
this.$set('error', data.error);
} else {
this.$set('file', data);
}
});
The exact error that I get is this:
2/2 NotFoundHttpException in Handler.php line 46:
No query results for model [App\File].
1/2 ModelNotFoundException in Builder.php line 129:
No query results for model [App\File].
But the Application doesn't even get to the controller, if I just return something from there the error is the same.
With Laravel routes, the order matters. Routes with dynamic segments like files/{file} or resource routes should always be defined after the ones that are static. Otherwise Laravel will interpret the share part in your URL as ID.
So, as you've figured out yourself you simply need to change the order of your routes:
Route::put('/files/share', 'FileController#test');
Route::resource('/files', 'FileController');
Thanks to lukasgeiter I checked my routes once more and had to define the /files/share route before my RESTful resource route.
I am new to laravel 4 framework but was previously working on CI and CakePHP, i have some problems with routes in it (i may sound nerd, so bear with me.)
-> If i have 3 controller userController,adminController,editorController and many methods inside them, do i need to define routes for every methods inside it (ofcourse i am not using ResourceFull controller for them). Can't i have something by which the methods can be accessed by using the controllername followed by method name like we do in other frameWork.
E.g usersController have manageUser method, i wnt to access it like
http://localhost/project/users/manageUser
-> What is use of defining a route using Route::controller('users', 'UserController'); or restfull controller?
Thanks in advance :)
If you write
Route::controller('users', 'UserController')
runs the default function (index of all the objects), but you can write:
Route::get('/users', 'userController#function');
or
Route::post('/users', 'userController#function');
this route shows to Laravel what controller and function can call when you write this route, the diference is if you pass the parameters with get or post mode.
Hope I help you