laravel giving incomprehensible(to me) http exception - php

I use laravel 4 and am not able to show a component :
this is a line from my routes
Route::resource('/', 'PostsController');
and this is my show function from PostsController.php
public function show($id) {
return "HI";
}
And This is the line that links to the function from my view
<h1>{{$post['title']}}</h1>
And It properly links to localhost:8000/show/1
But I'm amazingly getting a Not found HTTP exception from laravel.
How do I get this to work?

So the answer is that #NihalSahu is wrong (me) and that resourceful routing doesn't work like that it would be infinitely better so as to set the router to host/{id}

Related

The GET method is not supported for this route.Supported methods: HEAD

I just installed Laravel 8 and created new controller and route. when i try to use new route that i created which is working fine but route('/') is not working. giving me error
The GET method is not supported for this route. Supported methods: HEAD.
route/web.php
Route::get('/', function () {
return view('welcome');
});
Route::get('login', [LoginController::class,'loginShow'])->name('login');
LoginController
class LoginController extends Controller
{
function loginShow(){
return view('Login.login');
}
}
Route List
Problem Detail :
here i have 2 routes 1) mydomin or mydomin/ 2) myDomian/login
here myDomian/login is working as i want but when i try to use mydomin then i am getting
many time i face thing problem but sometime i fix anyway. But i want to know its real reason why it happen? so next time i will take case self. here mydomin is GET method route and i delcleared in web.php as GET. so why it is telling it is HEAD not get? Also note that before create a new route it was working in same way. so why now not? please tell me reason of this.
i got my solution using php artisan serve . so after that it is start working. but i a could not understand why it is not working without php artisan serve .... if any one has any reason please tell us.

Why laravel landing page route return MethodNotAllowedHttpException?

I'm using laravel 7.x.
since function(){return view(welcome);} will produce an error when I run php artisan route:cache, so I write this code below to replace function():
Route::get('/', 'WelcomeController#index')->name('welcome');
It run well on php artisan serve command.
But when i run directly from public folder, it produce exception MethodNotAllowedHttpException. I couldn't find why it happened, could you help me why it happened?
exception message:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: HEAD.
https://localhost/laravel-tester/public/
WelcomeController Method
public function index(){
return view('welcome');
}
::get registers the route for methods GET and HEAD by default. You are trying to access it with a GET request (as you should) but it does not return it. Possibly there is something wrong with your Router class, so please check your Routing\Router.php class against the method in the comment below.
https://stackoverflow.com/a/22119028/10187949

Why is my show function not working in Laravel 5.8

Below is the code in my route
Route::get('patients/{$patient}/','PatientController#show');
The above will not work in my browser , it will say 404 | not found with the url
below http://127.0.0.1:8000/patients/3
But
if I change my route to code below
Route::get('patients','PatientController#show');
I will not get any error , infact it will display the view for me.
What could be the problem? I am using Laravel 5.8
You have a typo in your route, {$patient} should be {patient}.
Route::get('patients/{patient}/','PatientController#show');
Then using model-route-binding, you will have the $patient model ready for you in your show() method,
public function show(Patient $patient){
return view('patients.show', ['patient' => '$patient']);
}
This is your route problem.
Route::get('/patients/{patient?}', 'PatientController#show');
You can use url like this
http://127.0.0.1:8000/patients/3
or
http://127.0.0.1:8000/patients
And your controller is also simple
public function show(Patient $patient=null){
return view('patients.show',compact('patient'));
}

Unable to access laravel 5.5 API route using Postman software

My api.php route is
Route::get('/allposts','PostController#index');
Controller function is and working with web.php Route file
public function index()
{
$posts= Post::all();
return PostResource::collection($posts);
}
my Resource is toArray function is
public function toArray($request)
{
return parent::toArray($request);
}
Postman link using GET are
"queuetest.com/api/allposts"
"http://queuetest.com/api/allposts"
both are not working
and getting Result in both Post man and browser: Sorry the page your looking for could not be found
Do you get something other than the Sorry the page you're looking for could not be found message when you do var_dump('test');die(); in your index method as the first line.
Edit: try to remove then / before /allPosts
Another edit: check in your RouteServiceProvider if the mapApiRoutes prefix is set to 'api'
If you are using the default route configuration that comes out of the box, you should place your route in routes/api.php if you want to access it in the /api namespace. Right now, the route should be accessible from http://queuetest.com/allposts.
This behavior can be configured in App\Providers\RouteServiceProviders.php. If you have a modified route configuration, there are numerous things that could cause this behaviour, and it is impossible to locate the problem without seeing more code.

Laravel 5.4 function index try using function show

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.

Categories