laravel cant find method in live server - php

i'm facing a weird error in my machine locally everything is working properly while when i throw the project in server live i have this problem BadMethodCallException which says cant find the method but the method actually it exist, i tried everything php artisan key:generate, composer dump-autoload, php artisan cache:config but with no success.
my route:
Route::get('/forgotpassword',[
'as' => "forgotpassword",
'uses' => "admin#forgotpassword"
]);
controller:
//Forgot Password
public function forgotpassword()
{
return view('page.forgotpassword');
}
And error i'm getting:
BadMethodCallException
Method App\Http\Controllers\admin::forgotpassword does not exist.

Try this:
Route::get('/forgotpassword',[
'as' => "forgotpassword",
'uses' => "Admin#forgotpassword"
]);
Remember: All class name is case-sensitive. XAMPP corrected this automatically.

usually this happens when you develop in windows but host it on Linux.
In Linux we have to also take care of the case sensitivity.
make sure your class name is same as you are referencing in your routes.
e.g
Route::get('/forgotpassword',[
'as' => "forgotpassword",
'uses' => "admin#forgotpassword"
]);
for the above given route you must have a controller name with lower case.
e.g
class admin extends Controller {}
Hope this helps

namespace App\Http\Controllers;
use App\Http\Controllers;
class Admin extends Controller {
}
Route
Route::get('/forgotpassword',[
'as' => "forgotpassword",
'uses' => "Admin#forgotpassword"
]);

Related

Laravel passport can't find ApproveAuthorizationController

I'm trying to setup a laravel application with oauth autorization by using the laravel passport functionality. I'm using the official tutorial (https://laravel.com/docs/master/passport). But now if I make a post request to '/oauth/authorize' the following error message occurs:
Class App\Http\Controllers\Laravel\Passport\Http\Controllers\ApproveAuthorizationController does not exist
I don't know what I've been doing wrong. I use the routes getting from 'Passport:routes' and no self defined routes.
I've already made a composer update, install and clear cache but nothing worked.
The problem get caused here:
/**
* Register the routes needed for authorization.
*
* #return void
*/
public function forAuthorization()
{
$this->router->group(['middleware' => ['web', 'auth']], function ($router) {
$router->get('/authorize', [
'uses' => 'AuthorizationController#authorize',
]);
$router->post('/authorize', [
'uses' => 'ApproveAuthorizationController#approve',
]);
$router->delete('/authorize', [
'uses' => 'DenyAuthorizationController#deny',
]);
});
}
I've already tried it by importing the missing class with a use statement but it still wont work.
Can somebody help me?
It looks like you're missing a use statement at the top of a controller or service proivder. Somewhere you have a class being used with out properly importing it first. That's why you're seeing the concatenated string like:
App\Http\Controllers\Laravel\Passport\Http\Controllers\ApproveAuthorizationController.
I assume what you need is this:
use Passport\Http\Controllers\ApproveAuthorizationController;
or Passport in Passport::routes is not being imported, one of the two. In AppServiceProvider:
use Laravel\Passport\Passport;

Sorry the page you're looking could not be found. Laravel 5.5

I have laravel 5.5. Everything is working fine in it. I can access all routes.
But somehow I cannot access the route "/interest/{$id}".
This is my route.
<?php
Route::get('/interest/{$id}', [
'uses' => 'IdeaController#createInterest'
])->name('interest.create')->middleware('auth');
I Can access every route accept this one. I hope this helps.
Remove the dollar sign from your route parameter:
Route::get('/interest/{id}', [
'uses' => 'IdeaController#createInterest'
])->name('interest.create')->middleware('auth');
Route::get('/interest/{id}', [
'uses' => 'IdeaController#createInterest'
])->name('interest.create')->middleware('auth');
//in controller use method
public function createInterest($id){
}

Laravel : BadMethodCallException Method [show] does not exist

(1/1) BadMethodCallException
Method [show] does not exist. in Controller.php (line 82)
I am new to Laravel and PHP and have been stuck on this error for a very long time with other questions not providing a solution. I was following an example (where the example worked) and made very little changes beside name changes.
Here is the code:
web.php file
Route::get('/', 'PagesController#home');
Route::get('faq', 'PagesController#faq');
Route::resource('support', 'UserInfoController');
UserInfoController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\UserInfo;
class UserInfoController extends Controller
{
//
public function create(){
$userInfo = new UserInfo;
return view('contact', ['userInfo' => $userInfo]);
}
public function store(Request $request){
$this->validate($request, [
'name' => 'required',
'email' => 'required',
'subject' => 'required',
'description' => 'required',
]);
UserInfo::create($request->all());
return redirect()->route('contact')->with('success','Enquiry has been
submitted successfully');
}
}
UserInfo.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class UserInfo extends Model {
protected $fillable = [
'name','email','subject','description',
];
}
The Route::resource is the one giving me the problem as I am trying to access the page support/contact. Would be very grateful if someone knew how to solve this.
That is because you are doing resource routes in your routes.php file that generates all the routes for the CRUD functions when you have to generate a route for the show method you find that it does not exist.
To solve it only creates the methods that you ask or, also you can define only the routes that you need.
The controller is trying to invoke the 'show' method - which you should have defined if you're going to load /support/{id} via GET in your browser. You can see the expected methods for a resource here:
https://laravel.com/docs/5.4/controllers#resource-controllers
You can also make your life somewhat easier by starting with a valid controller by using the built in generator:
php artisan make:controller UserInfoController --resource
If you don't want to supply ALL the methods, you have to specify, for example:
Route::resource('support', 'UserInfoController', ['only' => [
'create', 'store'
]]);
Have you added method Show to your Controller ? Route::Resource has 7 basic routes:
Verb Path Action Route Name
GET /support index support.index
GET /support/create create support.create
POST /support store support.store
GET /support/{support} show support.show
GET /support/{support}/edit edit support.edit
PUT /support/{support} update support.update
DELETE /support/{support} destroy support.destroy
As you see there is a route called show which will be default when you route to support so you must connect this route to it's method in the controller which is in resource case CONTROLLER/show, however in your case you're trying to get a static page from a prefix called support which is different from resources because show in resource handling dynamic results.
Use this syntax to get a page called contact from prefix called support
Route::prefix('support')->group(function () {
Route::get('contact', function () {
// Matches The "/UserInfoController/contact" URL
});
});

Using middleware route filer in Entrust for Laravel

I have used Entrust for laravel, everything works fine until I used the middleware route filter.
Like I said everything works fine apart from the middlware filter. I have added the routemiddleware array to kernel. So this is basically what the filter looks like, same thing that is found in the docs:
Route::group(['prefix' => 'admin', 'middleware' => ['role:admin']], function() {
Route::get('/', 'AdminController#welcome');
Route::get('/manage', ['middleware' => ['permission:manage-admins'], 'uses' => 'AdminController#manageAdmins']);
});
But I've got this error:
ReflectionException in Container.php line 779: Class role:admin does
not exist
after you finish installation, you need run composer dump-autoload ,and make sure you follow every step of the doc

Laravel route doesn't work

I am making basic route with controller but it doesnt work, I dont know why... Earyer worked for me but now doesnt...
Here is routes.php:
Route::get('/admin', array(
'as' => 'admin-login',
'uses' => 'AdminController#getAdminLogin'
));
Here is AdminController.php:
class AdminController extends BaseController {
public function getAdminLogin()
{
return View::make('admin.index');
}
}
When I type localhost/project/public/admin... It goes to localhost/admin
Why?
Why don't you use Laravel's own Web Server:
php artisan serve
And then, try this:
http://localhost:8000/admin/

Categories