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
Related
I have a little routing problem, that i can't solve in Codeigniter 4.
I try adding a parameter at deleting list item. But get the following error messages.
Error message at post routing: Controller or its method is not found:
\App\Controllers\Userfeed::delete
Error message at add or get routing: Controller or its method is not found:
\App\Controllers\Pages::index
controllers file directory:
the relevant part of the Route file (it's in the Config directory):
$routes->get('/', 'Pages/Home::index');
$routes->get('userfeed', 'Pages/UserFeed::index');
$routes->post('userfeed/add', 'Pages/UserFeed::add');
//$routes->add('userfeed/(:any)', 'Pages/UserFeed::delete');//this works fine
$routes->get('userfeed/(:any)', 'Pages/UserFeed::delete');//this works fine
//$routes->get('userfeed/(:any)', 'Pages/UserFeed::delete/$1');//this is not work, which is the goal
//$routes->post('userfeed/(:any)', 'Pages/UserFeed::delete/$1');//this is not work
//$routes->add('userfeed/(:any)', 'Pages/UserFeed::delete/$1');//this is not work
...
the relevant part of the controller:
namespace App\Controllers\Pages;
use App\Controllers\MainCtrl;
...
class UserFeed extends MainCtrl{
....
public function delete($id=FALSE)
{
var_dump('wooot?');
var_dump($id);
}
}
the view part:
....
<a class="badge badge-secondary" href="<?php echo base_url('userfeed/delete/'.$rss['id']);?>" >Töröl</a>
....
But if i make a copy from this controller in the root controller directory, it's working.
$routes->get('userfeed/delete/(:any)', 'UserFeed2::delete/$1');//it's working fine
If need more information let it with me know.
Thanks your help! :)
Note: Thank God, found the problem. :)
And one guess, one reward. =)
Try this one
$routes->get('userfeed/delete/(:any)', 'Pages\UserFeed::delete/$1');
The difference is the slash used. You must use a backslash () not forward (/)
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 have route:
Route::resource('admin/question', 'QuestionsController');
and function index:
public function index() {
return "Hello";
}
But when I try used index Laravel returned me the error:
Method [show] does not exist.
I'm using the link:
http://localhost:8012/siwz/siwz/public/admin/question
The server is WampServer program.
I can only use index function when I change route file:
Route::get('admin/question/index', 'QuestionsController#index');
Route::resource('admin/question', 'QuestionsController');
In Laravel version 5.3 I did not have to do it, it was enough to use:
Route::resource('.../...', '...Controller');
Actually, the URL is going to the correct function. admin/question should go to index. admin/question/{question} is the route that goes to show.
Take a look here and check how Laravel create Resource routes:
https://laravel.com/docs/5.4/controllers#resource-controllers
Since that you didn't provide your full routes. I am guessing that the link you were accessing is going to the wrong controller. You should check the ordering of the routes. Maybe you are accessing something like this on your route,
Route::resource('admin','AdminController');
And the AdminController doesn't have a method show(). Thats why laravel return that error.
Here's you can do
Comment out the rest of routes except route that you are accessing.
Try to reorder the affected routes. Maybe Laravel is confused with your 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
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