laravel 5 routing controller to different directory - laravel-5

Route:
Route::resource('call-plan', 'CustomerCallPlanController');
Class
<?php
namespace App\Http\Controllers\Customer;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use Html;
use Illuminate\Http\Request;
class CustomerCallPlanController extends CustomerBaseController
{
public function index()
{
dd('SUCCESS!');
}
And I expect to see 'SUCCESS' message in blank page but I see this instead:
ReflectionException in Container.php line 741:
Class App\Http\Controllers\CustomerCallPlanController does not exist
in Container.php line 741
at ReflectionClass->__construct('App\Http\Controllers\CustomerCallPlanController') in Container.php line 741
at Container->build('App\Http\Controllers\CustomerCallPlanController', array()) in Container.php line 631
at Container->make('App\Http\Controllers\CustomerCallPlanController', array()) in Application.php line 674
at Application->make('App\Http\Controllers\CustomerCallPlanController') in ControllerDispatcher.php line 85
at ControllerDispatcher->makeController('App\Http\Controllers\CustomerCallPlanController') in ControllerDispatcher.php line 57
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\CustomerCallPlanController', 'index') in Route.php line 203
I see the message in exception tell App\Http\Controllers\CustomerCallPlanController it makes sense because my controller in Customer folder which means it should be App\Http\Controllers\Customer\CustomerCallPlanController
How can I fix this

You can use a relative path:
Route::resource('call-plan', 'Customer\CustomerCallPlanController');
Check the docs under Controllers & Namespaces

Related

BadMethodCallException Method [validate] does not exist

furture more it says.
in Controller.php line 82.
at Controller->__call('validate', array(object(Request), array('email' => 'required|string', 'password' => 'required|string')))
in AuthenticatesUsers.php line 63
note:
every thing was working fine till yesterday morning.my laravel version is 5.4.36.
Put this line in your class
use ValidatesRequests;
Right below
class classname ...... {
use ValidatesRequests;
}
Your LoginController doesn't extend from the base Controller, App\Http\Controllers\Controller or this base class is missing a trait. This class was setup to use the Illuminate\Foundation\Validation\ValidatesRequests trait, which gives you the validate method.
If your base Controller does not use this trait, then you can add the use statement to use this trait so that you will have the validate method in all your Controllers.

Solving Uncaught ReflectionException: Class log does not exist in C:\......\Container.php:

I am experiencing an unexpected Reflection Exception error that class log does not exist. I am currently using Laravel 5.2. The addition of use log amongst namespaces into my controller hasn't solved this.
Fatal error: Uncaught ReflectionException: Class log does not exist in C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php:741
Stack trace:
#0 C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(741): ReflectionClass->__construct('log')
#1 C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(631): Illuminate\Container\Container->build('log', Array)
#2 C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(674): Illuminate\Container\Container->make('log', Array)
#3 C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(842): Illuminate\Foundation\Application->make('log')
#4 C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(805): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#5 C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(775): Illuminate\Conta in C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 741
controller.php
<?php
namespace App\Http\Controllers;
use Log;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesResources;
use Illuminate\Database\Eloquent\ModelNotFoundException;
class Controller extends BaseController
{
use AuthorizesRequests,AuthorizesResources, DispatchesJobs, ValidatesRequests;
}
routes.php
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
Route::get('/', function () {
return view('welcome');
});
Check for spaces in your .env or config files as suggested here
https://laracasts.com/discuss/channels/general-discussion/class-log-does-not-exist?page=2
enclose it with double quotes if any

FatalErrorException in Model.php line 986: Class 'App\Role' not found

My routes.php file is
<?php
use App\models\User;
use App\models\Permission;
use App\models\Role;
Route::get('/roles', function()
{
//code
}
and my role.php file is
<?php
namespace App\models;
use Zizaco\Entrust\EntrustRole;
class Role extends EntrustRole
{
}
and I found the error like this
FatalErrorException in Model.php line 986: Class 'App\Role' not found
The default Entrust config file looks for models inside the App namespace, not the App\models namespace. You need to publish the config file and update it accordingly:
'role' => 'App\models\Role',

Laravel 5.1 BadMethodCallException in Controller.php line 283 Method [create] does not exist

I want to create user by using social authentication like Facebook authentication and I followed this tutorial Socialite Authentication in Laravel 5.1 from youtube.
After using this tutorial I got an Exception which is
BadMethodCallException in Controller.php line 283:
Method [create] does not exist.
in Controller.php line 283
at Controller->__call('create', array(array('name' => null, 'email' => 'abdur.razzaq06#gmail.com', 'password' => '4dbf14f26a97584375b7b2c84b6a4786cb1b4a43'))) in SocialAuthController.php line 84
at SocialAuthController->create(array('name' => null, 'email' => 'abdur.razzaq06#gmail.com', 'password' => '4dbf14f26a97584375b7b2c84b6a4786cb1b4a43')) in SocialAuthController.php line 84
at SocialAuthController->github_Callback()
at call_user_func_array(array(object(SocialAuthController), 'github_Callback'), array()) in Controller.php line 256
at Controller->callAction('github_Callback', array()) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(SocialAuthController), object(Route), 'github_Callback') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
What can I do to fix it?
Here is my code:
app\routes.php
// facebook Sociolite
Route::get('/auth/facebook', 'Auth\SocialAuthController#redirectToProvider');
Route::get('callback_facebook', 'Auth\SocialAuthController#handleProviderCallback');
App\Http\Auth|SocialAuthController.php
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Illuminate\Foundation\Validation\ValidatesRequests;
use App\User;
use Validator;
//use ValidatesRequests;
use Socialite;
use Auth;
use redirect;
class SocialAuthController extends Controller
{
// For Facebook
public function redirectToProvider(){
return Socialite::driver('facebook')->redirect();
}
public function handleProviderCallback(){
$curl = curl_init();
curl_setopt($curl , CURLOPT_SSL_VERIFYPEER, false);
$user = Socialite::driver('facebook')->user();
$data = ['name'=>$user->name, 'email'=>$user->email, 'password'=>$user->token];
$userDB = User::where('email',$user->email)->first();
if (!is_null($userDB)){
Auth::login($userDB);
}
else{
Auth::login($this->create($data)); // line 84
// Auth::login($this->data($data));
}
return redirect('/pages/profile');
}
}
vendor/laravel/framework/src/Illuminate/Routing/Controller.php
<?php
namespace Illuminate\Routing;
use Closure;
use BadMethodCallException;
use Illuminate\Support\Str;
use InvalidArgumentException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
abstract class Controller
{
public function __call($method, $parameters)
{
throw new BadMethodCallException("Method [$method] does not exist."); // line 283
}
}
Line 84 calls the create method of your controller. Is it defined? The exception you get implies that it isn't.
You have to actually implement the create method in your SocialAuthController

Laravel 5.1 social Authentication is not working properly

Recently i am working on laravel 5.1 framework and trying to make user login by Social Authentication like facebook login ..
i followed this tutorial from youtube Laravel 5.1 Socialite Authentication
but get this Exception
InvalidStateException in AbstractProvider.php line 191:
in AbstractProvider.php line 191
at AbstractProvider->user() in SocialAuthController.php line 61
at SocialAuthController->github_Callback()
at call_user_func_array(array(object(SocialAuthController), 'github_Callback'), array()) in Controller.php line 256
at Controller->callAction('github_Callback', array()) in ControllerDispatcher.php line 164
Here is my code
// facebook Sociolite for routing
Route::get('/auth/facebook', 'Auth\SocialAuthController#redirectToProvider');
Route::get('callback_facebook', 'Auth\SocialAuthController#handleProviderCallback');
// AuthController
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Socialite;
use Auth;
use redirect;
class AuthController extends Controller
{
class SocialAuthController extends Controller{
// For Facebook
public function redirectToProvider(){
return Socialite::driver('facebook')->redirect();
}
public function handleProviderCallback(){
$curl = curl_init();
curl_setopt($curl , CURLOPT_SSL_VERIFYPEER, false);
$user = Socialite::driver('facebook')->user();
$data = ['name'=>$user->name, 'email'=>$user->email, 'password'=>$user->token];
$userDB = User::where('email',$user->email)->first();
if (!is_null($userDB)){
Auth::login($userDB);
}
else{
Auth::login($this->create($data));
}
return redirect('/pages/profile');
}
}
}
config\service.php
'facebook' => [
'client_id' => '513845902100524',
'client_secret' => '135699237e16cd3a50d2cbfec3a5e58c',
'redirect' => 'http://localhost:8000/callback_facebook',
],
You can get detail documentation from laravel official site. Socialite tutorial here.

Resources