Post method not working inspite of adding CSRF Token - laravel

I am new to Laravel, I was trying to use a form and thus used post method in it after adding CSRF Token. Also I have downloaded form builder package and have made all the adjustments needed for the same. But somehow, the post method in the routes is not working. Although I tried using get and any method in routes and they worked perfect fine.
Controller:
use App\Http\Controllers\Controller;
class AdminController extends Controller
{
public function index()
{
echo "admin controller";
}
public function formSubmit()
{
echo "Form Submit Method";
return view('layouts\formView');
}
}
View:
#extends('layouts\masterLayout')
#section('head')
{!!Form::open(['route'=>'f.submit'])!!}
<input type="hidden" name="_token" value="{{ csrf_token() }}">
{!!Form::text('field-one')!!}
{!!Form::submit('')!!}
#endsection
Route:
Route::post('form-submit',['uses'=>'Admin\AdminController#formSubmit', 'as'=>'f.submit']);
Error: Stack Trace
in RouteCollection.php line 218
at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 205
at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 158
at RouteCollection->match(object(Request)) in Router.php line 821
at Router->findRoute(object(Request)) in Router.php line 691
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 53

Change
{!!Form::open(['route'=>'f.submit'])!!}
to
{!!Form::open(['route'=>'f.submit', 'method' => 'POST'])!!}
Reason is probably obvious ;-)
EDIT
Can you change the signature of the formSubmit function to this:
public function formSubmit(Request $request)
{
echo "Form Submit Method";
return view('layouts\formView');
}

Instead of
Use as follow that will create Input field with unique token
{{csrf_token()}}
Change Route To
Route::post('form-submit',[ 'as'=>'f.submit','uses'=>'Admin\AdminController#formSubmit' ]);
change View Method
return view('layouts\formView');
Like
return view('layouts.formView');
For E.g
return view('YourFolderName.FileName');

Related

Laravel 9 custom FormRequest throws "Object of type Illuminate\Session\Store is not callable"

Im testing out the new laravel 9 and I sadly come across this surprise.
After using PHP artisan make:request UpdateUserRequest and setting this as my request class on the incoming update function, this error happens:
[2022-02-09 12:42:08] local.ERROR: Object of type Illuminate\Session\Store is not callable {"userId":2,"exception":"[object] (Error(code: 0): Object of type Illuminate\\Session\\Store is not callable at /app/vendor/symfony/http-foundation/Request.php:698)
My code
UserController:
public function update(UpdateUserRequest $request){}
UpdateUserRequest:
{
/**
* Determine if the user is authorized to make this request.
*
* #return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* #return array
*/
public function rules()
{
return [
//
];
}
}
What I did so far to try to fix the problem is see when it happens.
When I change the extended class of my UpdateUserRequest from FormRequest to Request the error doesn't happen.
so it seems to be in FormRequest.
Added the 'web' middleware to my routes also did not solve the problem (suggestion from the internet)
I can ofcourse create my own class that doesn't extend anything and just validates it by using the regular Request class but that's ofcourse not how its supposed to work.
Complete stacktrace:
Error:
Object of type Illuminate\Session\Store is not callable
at /app/vendor/symfony/http-foundation/Request.php:698
at Symfony\Component\HttpFoundation\Request->getSession()
(/app/vendor/laravel/framework/src/Illuminate/Http/Request.php:424)
at Illuminate\Http\Request::createFrom(object(Request), object(UpdateUserRequest))
(/app/vendor/laravel/framework/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php:34)
at Illuminate\Foundation\Providers\FormRequestServiceProvider->Illuminate\Foundation\Providers\{closure}(object(UpdateUserRequest), object(Application))
(/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:1269)
at Illuminate\Container\Container->fireCallbackArray(object(UpdateUserRequest), array(object(Closure)))
(/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:1216)
at Illuminate\Container\Container->fireResolvingCallbacks('App\\Http\\Requests\\UpdateUserRequest', object(UpdateUserRequest))
(/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:778)
at Illuminate\Container\Container->resolve('App\\Http\\Requests\\UpdateUserRequest', array(), true)
(/app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:854)
at Illuminate\Foundation\Application->resolve('App\\Http\\Requests\\UpdateUserRequest', array())
(/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:694)
at Illuminate\Container\Container->make('App\\Http\\Requests\\UpdateUserRequest', array())
(/app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:839)
at Illuminate\Foundation\Application->make('App\\Http\\Requests\\UpdateUserRequest')
(/app/vendor/laravel/framework/src/Illuminate/Routing/RouteDependencyResolverTrait.php:79)
at Illuminate\Routing\ControllerDispatcher->transformDependency(object(ReflectionParameter), array('user' => '10'), object(stdClass))
(/app/vendor/laravel/framework/src/Illuminate/Routing/RouteDependencyResolverTrait.php:48)
at Illuminate\Routing\ControllerDispatcher->resolveMethodDependencies(array('user' => '10'), object(ReflectionMethod))
(/app/vendor/laravel/framework/src/Illuminate/Routing/RouteDependencyResolverTrait.php:28)
at Illuminate\Routing\ControllerDispatcher->resolveClassMethodDependencies(array('user' => '10'), object(UserController), 'update')
(/app/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:41)
at Illuminate\Routing\ControllerDispatcher->dispatch(object(Route), object(UserController), 'update')
(/app/vendor/laravel/framework/src/Illuminate/Routing/Route.php:261)
at Illuminate\Routing\Route->runController()
(/app/vendor/laravel/framework/src/Illuminate/Routing/Route.php:204)
at Illuminate\Routing\Route->run()
(/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:695)
at Illuminate\Routing\Router->Illuminate\Routing\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:128)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/spatie/laravel-permission/src/Middlewares/RoleMiddleware.php:27)
at Spatie\Permission\Middlewares\RoleMiddleware->handle(object(Request), object(Closure), 'superadmin')
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:50)
at Illuminate\Routing\Middleware\SubstituteBindings->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php:44)
at Illuminate\Auth\Middleware\Authenticate->handle(object(Request), object(Closure), 'web')
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php:44)
at Illuminate\Auth\Middleware\Authenticate->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:78)
at Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49)
at Illuminate\View\Middleware\ShareErrorsFromSession->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:121)
at Illuminate\Session\Middleware\StartSession->handleStatefulRequest(object(Request), object(Store), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:64)
at Illuminate\Session\Middleware\StartSession->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37)
at Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:67)
at Illuminate\Cookie\Middleware\EncryptCookies->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103)
at Illuminate\Pipeline\Pipeline->then(object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:697)
at Illuminate\Routing\Router->runRouteWithinStack(object(Route), object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:672)
at Illuminate\Routing\Router->runRoute(object(Request), object(Route))
(/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:636)
at Illuminate\Routing\Router->dispatchToRoute(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:625)
at Illuminate\Routing\Router->dispatch(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:167)
at Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:128)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21)
at Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php:31)
at Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21)
at Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php:40)
at Illuminate\Foundation\Http\Middleware\TrimStrings->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27)
at Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php:86)
at Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/fruitcake/laravel-cors/src/HandleCors.php:38)
at Fruitcake\Cors\HandleCors->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php:39)
at Illuminate\Http\Middleware\TrustProxies->handle(object(Request), object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103)
at Illuminate\Pipeline\Pipeline->then(object(Closure))
(/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:142)
at Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(object(Request))
(/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:111)
at Illuminate\Foundation\Http\Kernel->handle(object(Request))
(/app/public/index.php:52)
This was indeed no laravel 9 issue.
This issue was from upgrading laravel-dev to official release.
Since there was not that much code made, I decided to clone the new laravel 9 repo, and push my changes manually to this new repo. Then all worked fine.

Laravel Lumen ReflectionException

I already had a look at other post about how to fix the ReflectionException issue in laravel Lumen, using this:
$request = Illuminate\Http\Request::capture();
$app->run($request);
However it is not solving my problem. I have a controller called AccountController.php and placed in app/Http/Controllers/Account folder and here is the code:
<?php
namespace App\Http\Controllers\Account;
use App\Account;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class AccountController extends Controller {
public function createNewAccount(Request $request) {
$newAccount = Account::create($request->all());
return response()->json($newAccount);
}
}
And this is my route file placed in /routes/web.php:
<?php
$app->get('/hello', function () use ($app) {
return 'Hello World!';
});
$app->group(['prefix' => 'api/v1','namespace' => 'App\Http\Controllers\Account'], function($app)
{
$app->post('account','AccountController#createNewAccount');
});
When I test with Postman the get request which returns a simple 'Hello World' is working fine, but the POST call to api/v1/account/createNewAccount will always fail whatever I do:
ReflectionException in Container.php line 681:
Class App\Http\Controllers\App\Http\Controllers\Account\AccountController does not exist
in Container.php line 681
at ReflectionClass->__construct('App\Http\Controllers\App\Http\Controllers\Account\AccountController') in Container.php line 681
at Container->build('App\Http\Controllers\App\Http\Controllers\Account\AccountController') in Container.php line 565
at Container->make('App\Http\Controllers\App\Http\Controllers\Account\AccountController') in Application.php line 208
at Application->make('App\Http\Controllers\App\Http\Controllers\Account\AccountController') in RoutesRequests.php line 677
at Application->callControllerAction(array(true, array('uses' => 'App\Http\Controllers\App\Http\Controllers\Account\AccountController#createNewAccount'), array())) in RoutesRequests.php line 644
at Application->callActionOnArrayBasedRoute(array(true, array('uses' => 'App\Http\Controllers\App\Http\Controllers\Account\AccountController#createNewAccount'), array())) in RoutesRequests.php line 629
at Application->handleFoundRoute(array(true, array('uses' => 'App\Http\Controllers\App\Http\Controllers\Account\AccountController#createNewAccount'), array())) in RoutesRequests.php line 528
at Application->Laravel\Lumen\Concerns{closure}() in RoutesRequests.php line 782
at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 534
at Application->dispatch(object(Request)) in RoutesRequests.php line 475
at Application->run(object(Request)) in index.php line 29
I am using "laravel/lumen-framework": "5.4.*".
There is no reply to this particular issue, I decided to build my API with Dingo API: https://github.com/dingo/api It is a good package to build API with Laravel/lumen. They created their own routing system and things are going much better since.

Why am I receiving a Route Collection error when inserting data?

When I try to insert data in Laravel 5.3 below error shown
Whoops, looks like something went wrong.
1/1 MethodNotAllowedHttpException in RouteCollection.php line 218:
in RouteCollection.php line 218
at RouteCollection->methodNotAllowed(array('GET', 'HEAD')) in RouteCollection.php line 205
at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD')) in RouteCollection.php line 158
at RouteCollection->match(object(Request)) in Router.php line 755
at Router->findRoute(object(Request)) in Router.php line 610
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 53
My Controller Code
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\userCreate;
public function store(Request $request)
{
$newUser = new userCreate;
$newUser ->fname = $request->fname;
$newUser ->lname = $request->lname;
$newUser ->email = $request->email;
$newUser ->password = $request->password;
$newUser ->utype = $request->utype;
$newUser->save();
//return redirect('/');
}
I'll look to post my route here:
Make sure your method is POST when accessing the route that creates a new user.
Try it...I think you are using resource controller so routing may be fine.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\userCreate;
public function store(Request $request)
{
$newUser = new userCreate;
$newUser ->fname = $request->input('fname');
$newUser ->lname = $request->input('lname');
$newUser ->email = $request->input('email');
$newUser ->password = $request->input('password');
$newUser ->utype = $request->input('utype');
$newUser->save();
//return redirect('/');
}
Use POST method when accessing the route that creates a new user.
Route::post('/store', 'NameController#store');
your route should be as below :
Route::resource('store','ControllerName');
if still not working, add your routes.php to Question.

laravel guzzlehttp - Server Exception in RequestException.php

I am getting ServerException in RequestException.php line 107 when I make POST request to my API. I get following error -
Server error: POST http://10.10.1.40:3000/auth/register resulted in a 500 Internal Server Error response:
{"statusCode":500,"errorMessage":"[object Object]"}.
I tried sending post request from REST Client and it works.
Following is the trace
in RequestException.php line 107 at RequestException::create(object(Request), object(Response)) in Middleware.php line 65
at Middleware::GuzzleHttp\{closure}(object(Response)) in Promise.php line 199
at Promise::callHandler('1', object(Response), array(object(Promise), object(Closure), null)) in Promise.php line 152
at Promise::GuzzleHttp\Promise\{closure}() in TaskQueue.php line 60
at TaskQueue->run(true) in Promise.php line 240
at Client->request('POST', 'http://10.10.1.40:3000/auth/register', array('body' => '{"firstName":"abc","lastName":"ab"}')) in RegisterController.php line 30
at RegisterController->postRegisterForm(object(Request))
Following is my controller code
class RegisterController extends Controller{
public function postRegisterForm(Request $request){
$jsonData = json_encode($_POST);
$client = new Client();
$res = $client->request('POST','10.10.1.40:3000/auth/register', ['body' => $jsonData]);
echo $res->getStatusCode();
echo $res->getBody();
}
}
Any suggestions?
You are right #ShaunBramley. I missed out sending the content type header in request. Adding following code works -
$headers = ['Content-Type' => 'application/json'];
$res = $client->request('POST', 'http://10.10.1.40:3000/auth/register', ['headers'=>$headers,'body' => $jsonData]);

Laravel 5 Auth: User must implement CanResetPassword interface

I've successfully implemented Laravel's Auth for Registration, Login and Logout. However, I'm having quite a bit of difficulty resolving the following error trying to implement the password reset functionality.
Error: User must implement CanResetPassword interface.
I believe my User class is configured properly:
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract,
CanResetPasswordContract {
use Authenticatable, CanResetPassword;
...
}
I'm not using Eloquent, so I have the following in config/auth.php:
'driver' => 'database'
Does anyone have any idea why I'm getting the "User must implement CanResetPassword interface" error?
Thanks much!
EDIT: Adding Stack Trace:
UnexpectedValueException in PasswordBroker.php line 237:
User must implement CanResetPassword interface .
in PasswordBroker.php line 237
at PasswordBroker->getUser( array('email' => 'admin2#beaudini.com')) in PasswordBroker.php line 81
at PasswordBroker->sendResetLink (array('email' => 'admin2#beaudini.com'), object(Closure)) in Facade .php line 217
at Facade::__callStatic('sendResetLink' , array(array('email' => 'admin2#beaudini.com'), object(Closure))) in ResetsPasswords.php line 35
at Password::sendResetLink(array ('email' => 'admin2#beaudini.com'), object(Closure)) in ResetsPasswords .php line 35
at PasswordController->postEmail (object(Request))
at call_user_func_array(array(object(PasswordController), 'postEmail'), array( object(Request))) in Controller.php line 256
at Controller->callAction('postEmail', array(object(Request))) in ControllerDispatcher .php line 164
at ControllerDispatcher->call (object(PasswordController), object(Route), 'postEmail') 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)) in RedirectIfAuthenticated.php line 41
at RedirectIfAuthenticated->handle(object(Request), object(Closure))
at call_user_func_array(array(object(RedirectIfAuthenticated), 'handle'), array (object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure }(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack (object(PasswordController), object(Route), object(Request), 'postEmail') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch (object(Route), object(Request), 'App\Http\Controllers\Auth\PasswordController', 'postEmail') in Route.php line 203
at Route->runWithCustomDispatcher(object (Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 704
at Router->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))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 706
at Router->runRouteWithinStack(object< /em>(Route), object(Request)) in Router.php line 671
at Router->dispatchToRoute(object (Request)) in Router.php line 631
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http \{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure }(object(Request)) in Debugbar.php line 49
at Debugbar->handle(object (Request), object(Closure ))
at call_user_func_array(array(object(Debugbar), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure }(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object (Request), object(Closure ))) in Pipeline .php line 124
at Pipeline->Illuminate\Pipeline\{closure }(object(Request)) in ShareErrorsFromSession .php line 49
at ShareErrorsFromSession ->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure }(object(Request)) in StartSession.php line 62< /a>
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline .php line 124
at Pipeline->Illuminate\Pipeline\{closure }(object(Request)) in AddQueuedCookiesToResponse .php line 37
at AddQueuedCookiesToResponse ->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array (object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure }(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle (object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline .php line 124
at Pipeline->Illuminate\Pipeline\{closure }(object(Request)) in CheckForMaintenanceMode .php line 42
at CheckForMaintenanceMode ->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure }(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter (object(Request)) in Kernel.php line 87
at Kernel->handle(object( Request)) in index.php line 54
I faced this problem in laravel 5.2, and I found a solution like as:
<?php
namespace App;
use Eloquent;
// use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\CanResetPassword as
CanResetPasswordContract;
class User extends Eloquent implements
Authenticatable,CanResetPasswordContract
{
use AuthenticableTrait,CanResetPassword;
.......
.......
}
Follow your stack trace.
PasswordBroker.php line 237
https://github.com/laravel/framework/blob/5.1/src/Illuminate/Auth/Passwords/PasswordBroker.php#L237
Fails because DatabaseUserProvider's retrieveByCredentials returns a GenericUser object, not your User class object.
https://github.com/laravel/framework/blob/5.1/src/Illuminate/Auth/DatabaseUserProvider.php#L99
What this means, basically, is that the password reminder functionality that Laravel comes with is only supported by the eloquent auth driver. You can't use it with the database driver. Your options are
switch to Eloquent
build out password resets by yourself, or
add your own custom auth driver
Inside of a service provider (AppServiceProvider, or create a new one):
Auth::extend('custom', function($app) {
return new CustomUserProvider($app['database.connection']);
});
It might be as simple as extending the database user provider and overriding getGenericUser to use your class instead.
class CustomUserProvider extends \Illuminate\Auth\DatabaseUserProvider
{
protected function getGenericUser($user) {
if ($user !== null) {
return new \App\User((array) $user);
}
}
}
The below should work in Any Model You Created
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class customer extends Model implements AuthenticatableContract,CanResetPasswordContract
{
//protected $primaryKey = 'customerId';
use AuthenticableTrait,CanResetPassword;
use ValidatesRequests;
protected $fillable=['name','email','password','country','favorite','gender','image'];
protected $hidden = [
'password', 'remember_token',
];
}
hope it helps

Resources