Class not found in job with protected variable - php

I'm trying to create a Job, but when i set the line:
protected $param;
to pass the data from __construct to handle() I start getting this error:
Class not found
When I removed the protected $param; line, the Job works perfectly. But I'm not able to get the data. What can I do to fix this?
<?php
namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Repositories\ProductRepository;
class ImportProducts extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
protected $param;
/**
* Create a new job instance.
*
* #return void
*/
public function __construct($param)
{
$this->param = $param;
}
/**
* Execute the job.
*
* #return void
*/
public function handle()
{
//$products = $this->param['products'];
exit();
}
}
This is the entire error message:
Whoops, looks like something went wrong.
1/1
ReflectionException in Container.php line 734:
Class does not exist
in Container.php line 734
at ReflectionClass->__construct('') in Container.php line 734
at Container->build('', array()) in Container.php line 629
at Container->make('', array()) in Application.php line 697
at Application->make('') in Job.php line 154
at Job->resolve('') in Job.php line 210
at Job->failed() in SyncQueue.php line 153
at SyncQueue->handleFailedJob(object(SyncJob)) in SyncQueue.php line 36
at SyncQueue->push(object(ImportProducts), '', 'upload_products_file') in Queue.php line 40
at Queue->pushOn('upload_products_file', object(ImportProducts)) in Dispatcher.php line 135
at Dispatcher->pushCommandToQueue(object(SyncQueue), object(ImportProducts)) in Dispatcher.php line 117
at Dispatcher->dispatchToQueue(object(ImportProducts)) in Dispatcher.php line 66
at Dispatcher->dispatch(object(ImportProducts)) in DispatchesJobs.php line 17
at Controller->dispatch(object(ImportProducts)) in ProductController.php line 656
at ProductController->importProducts(object(Request))
at call_user_func_array(array(object(ProductController), 'importProducts'), array(object(Request))) in Controller.php line 80
at Controller->callAction('importProducts', array(object(Request))) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(ProductController), object(Route), 'importProducts') in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{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 96
at ControllerDispatcher->callWithinStack(object(ProductController), object(Route), object(Request), 'importProducts') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\ProductController', 'importProducts') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 724
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
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 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)) 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 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)) in StartSession.php line 64
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 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)) 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 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)) 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 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 103
at Pipeline->then(object(Closure)) in Router.php line 726
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
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 103
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 54

When a job use SerializesModels trait expect a Eloquent model in the constructor.
You gave something different from an Eloquent Model in the constructor and Laravel, because the trait SerializesModels is trying to reconstruct the Eloquent object from the class of $param, but it cannot find it.
Try to remove SerializesModels from the traits of the job.

Related

Laravel 5.2 appear weird : Method [validateNickName] does not exist

Version:Laravel 5.2
issue:
BadMethodCallException in Validator.php line 3295:
Method [validateNickName] does not exist.
in Validator.php line 3295
at Validator->__call('validateNickName', array('nick_name', 'chenmin', array(), object(Validator))) in Validator.php line 485
at Validator->validateNickName('nick_name', 'chenmin', array(), object(Validator)) in Validator.php line 485
at Validator->validate('nick_name', 'nick_name') in Validator.php line 425
at Validator->passes() in Validator.php line 450
at Validator->fails() in ValidatesRequests.php line 53
at Controller->validate(object(Request), array('nick_name' => 'required|nick_name|unique:users|max:30', 'cellphone' => 'required|cellphone|unique:users|numeric|phone_number|size:11', 'captcha' => 'required|numeric|size:6', 'password' => 'required|min:6|max:30')) in UserController.php line 19
at UserController->postSignUp(object(Request))
at call_user_func_array(array(object(UserController), 'postSignUp'), array(object(Request))) in Controller.php line 80
at Controller->callAction('postSignUp', array(object(Request))) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(UserController), object(Route), 'postSignUp') in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{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 96
at ControllerDispatcher->callWithinStack(object(UserController), object(Route), object(Request), 'postSignUp') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\UserController', 'postSignUp') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 724
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
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 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)) 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 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)) in StartSession.php line 64
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 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)) 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 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)) 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 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 103
at Pipeline->then(object(Closure)) in Router.php line 726
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
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 103
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 54
source code:
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
public function postSignUp(Request $request)
{
$this->validate($request, [
'nick_name' => 'required|nick_name|unique:users|max:30',
'cellphone' => 'required|cellphone|unique:users|numeric|phone_number|size:11',
'captcha' => 'required|numeric|size:6',
'password' => 'required|min:6|max:30'
]);
.......
when I test the input from ,met a weird issue:BadMethodCallException in Validator.php line 3295:Method [validateNickName] does not exist.
who can help me to solve it ?thanks a lot!
nickn_name and cell_phone and phone_number are not validation rules?
so you cannot put them in the rule string. Your validation rules should looks as follow:
$this->validate($request, [
'nick_name' => 'required|unique:users|max:30',
'cellphone' => 'required|unique:users|numeric|size:11',
'captcha' => 'required|numeric|size:6',
'password' => 'required|min:6|max:30'
]);
I think is because you are using snake_case for nick_name, and somehow the validator thinks that you are calling a custom validation rule called nickName (bits of Laravel always convert snake_case to camelCase when helpers are called)... why would you call nickname nick_name ? In english I think is just one word...

Request validation error on production, not on local

So i've search the farthest reaches of the internet and come up with nothing. Please help!
I am developing locally on my Mac, all is fine.
When I push the site to production (CentOS7 VPS) I get the following error:
BadMethodCallException in Validator.php line 3162:
Method [validatePublication] does not exist.
Here is my app/Services/Validation/CustomValidation.php
```
use Illuminate\Validation\Validator;
class CustomValidation extends Validator {
//added only for test
public function validateCartRow($attribute, $value, $parameters)
{
$valid = (is_null(\Cart::get($value))) ? false : true;
return $valid;
}
public function validatePublication($attribute, $value, $parameters)
{
$valid = (\PublisherAPI::publicationByID($value) == false) ? false : true;
return $valid;
}
}
```
Here is my app/Providers/ValidationServiceProvider.php
```
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Services\Validation\CustomValidation;
use Illuminate\Validation\Validator;
class ValidationServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* #return void
*/
public function boot()
{
$this->app->validator->resolver(function($translator, $data, $rules, $messages)
{
return new \App\Services\Validation\CustomValidation($translator, $data, $rules, $messages);
});
}
/**
* Register the application services.
*
* #return void
*/
public function register()
{
//
}
}
```
Here is my app/Http/Requests/Cart/addToCartRequest.php
```
namespace App\Http\Requests\Cart;
use App\Http\Requests\Request;
class addToCartRequest extends Request
{
/**
* 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 [
'row_publication_id' => 'required|string|numeric|publication',
'row_price_key' => 'required|string|numeric',
];
}
}
```
This is the request that is failing on production. Again, I stress this is not a problem on my local Mac.
Any thoughts? I'm stumped...
Thanks!
UPDATE: Stack trace...
in Validator.php line 3265
at Validator->__call('validatePublication', array('row_publication_id', '4', array(), object(Validator))) in Validator.php line 485
at Validator->validatePublication('row_publication_id', '4', array(), object(Validator)) in Validator.php line 485
at Validator->validate('row_publication_id', 'publication') in Validator.php line 425
at Validator->passes() in ValidatesWhenResolvedTrait.php line 24
at FormRequest->validate() in FoundationServiceProvider.php line 41
at FoundationServiceProvider->Illuminate\Foundation\Providers\{closure}(object(addToCartRequest), object(Application)) in Container.php line 1031
at Container->fireCallbackArray(object(addToCartRequest), array(object(Closure))) in Container.php line 996
at Container->fireResolvingCallbacks('App\Http\Requests\Cart\addToCartRequest', object(addToCartRequest)) in Container.php line 648
at Container->make('App\Http\Requests\Cart\addToCartRequest', array()) in Application.php line 697
at Application->make('App\Http\Requests\Cart\addToCartRequest') in RouteDependencyResolverTrait.php line 85
at ControllerDispatcher->transformDependency(object(ReflectionParameter), array(), array()) in RouteDependencyResolverTrait.php line 59
at ControllerDispatcher->resolveMethodDependencies(array(), object(ReflectionMethod)) in RouteDependencyResolverTrait.php line 42
at ControllerDispatcher->resolveClassMethodDependencies(array(), object(CartController), 'addToCart') in ControllerDispatcher.php line 144
at ControllerDispatcher->call(object(CartController), object(Route), 'addToCart') in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{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 96
at ControllerDispatcher->callWithinStack(object(CartController), object(Route), object(Request), 'addToCart') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\Cart\CartController', 'addToCart') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 724
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SessionTimeout.php line 58
at SessionTimeout->handle(object(Request), object(Closure))
at call_user_func_array(array(object(SessionTimeout), '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)) 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 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)) in StartSession.php line 62
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 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)) 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 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)) 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 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 103
at Pipeline->then(object(Closure)) in Router.php line 726
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
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 103
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 54
Turns out it was a filename in app.php when registering the service provider.
I missed it as on local, the filename was correct. However I have a merge-driver setup that I completely forgot about preventing app.php being merged with staging (because of the application URL), so the error persisted.
I think I need to move the application URL to an environment variable and load the relevant config, getting rid of the merge driver.
Thanks to the guys at Laracasts for helping me get to the bottom of this..
https://laracasts.com/discuss/channels/laravel/error-on-production-not-on-local

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'app.articles' doesn't exist (SQL: select * from `articles`)

I was trying to create my db to laravel application but getting this error.
I was following this here tutorial.
I am unable to access my article database but i can access anything from User.php predefined model.
route.php
use App\article;
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::get('article', function () {
echo article::all();
});
article.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class article extends Model
{
}
in Connection.php line 673
at Connection->runQueryCallback('select * from `articles`', array(), object(Closure)) in Connection.php line 629
at Connection->run('select * from `articles`', array(), object(Closure)) in Connection.php line 342
at Connection->select('select * from `articles`', array(), true) in Builder.php line 1508
at Builder->runSelect() in Builder.php line 1494
at Builder->get(array('*')) in Builder.php line 596
at Builder->getModels(array('*')) in Builder.php line 303
at Builder->get(array('*')) in compiled.php line 10366
at Model::all() in routes.php line 20
at RouteServiceProvider->{closure}()
at call_user_func_array(object(Closure), array()) in compiled.php line 8415
at Route->runCallable(object(Request)) in compiled.php line 8405
at Route->run(object(Request)) in compiled.php line 8121
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 3176
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9838
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)) in compiled.php line 13274
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9838
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)) in compiled.php line 11822
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9838
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)) in compiled.php line 13009
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9838
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)) in compiled.php line 12946
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9838
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 compiled.php line 9828
at Pipeline->then(object(Closure)) in compiled.php line 8122
at Router->runRouteWithinStack(object(Route), object(Request)) in compiled.php line 8113
at Router->dispatchToRoute(object(Request)) in compiled.php line 8103
at Router->dispatch(object(Request)) in compiled.php line 2400
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 compiled.php line 3237
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9838
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 compiled.php line 9828
at Pipeline->then(object(Closure)) in compiled.php line 2347
at Kernel->sendRequestThroughRouter(object(Request)) in compiled.php line 2331
at Kernel->handle(object(Request)) in index.php line 54
at require_once('C:\xampp\htdocs\Laravel_apps\App\public\index.php') in server.php line 21
1/2
PDOException in Connection.php line 333:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'app.articles' doesn't exist
in Connection.php line 333
at PDO->prepare('select * from `articles`') in Connection.php line 333
at Connection->Illuminate\Database\{closure}(object(MySqlConnection), 'select * from `articles`', array()) in Connection.php line 666
at Connection->runQueryCallback('select * from `articles`', array(), object(Closure)) in Connection.php line 629
at Connection->run('select * from `articles`', array(), object(Closure)) in Connection.php line 342
at Connection->select('select * from `articles`', array(), true) in Builder.php line 1508
at Builder->runSelect() in Builder.php line 1494
at Builder->get(array('*')) in Builder.php line 596
at Builder->getModels(array('*')) in Builder.php line 303
at Builder->get(array('*')) in compiled.php line 10366
at Model::all() in routes.php line 20
at RouteServiceProvider->{closure}()
at call_user_func_array(object(Closure), array()) in compiled.php line 8415
at Route->runCallable(object(Request)) in compiled.php line 8405
at Route->run(object(Request)) in compiled.php line 8121
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 3176
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9838
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)) in compiled.php line 13274
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9838
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)) in compiled.php line 11822
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9838
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)) in compiled.php line 13009
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9838
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)) in compiled.php line 12946
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9838
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 compiled.php line 9828
at Pipeline->then(object(Closure)) in compiled.php line 8122
at Router->runRouteWithinStack(object(Route), object(Request)) in compiled.php line 8113
at Router->dispatchToRoute(object(Request)) in compiled.php line 8103
at Router->dispatch(object(Request)) in compiled.php line 2400
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 compiled.php line 3237
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9838
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 compiled.php line 9828
at Pipeline->then(object(Closure)) in compiled.php line 2347
at Kernel->sendRequestThroughRouter(object(Request)) in compiled.php line 2331
at Kernel->handle(object(Request)) in index.php line 54
at require_once('C:\xampp\htdocs\Laravel_apps\App\public\index.php') in server.php line 21
In your model 'article.php' do this.
namespace App;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
protected $table = 'article';
}
It will work for your 'article' table.

Method [validate] does not exist error in laravel 5.2

I have just started learning laravel.
I am using laravel 5.2.29
I am getting error when running the code:
Whoops, looks like something went wrong.
BadMethodCallException in Controller.php line 107:
Method [validate] does not exist.
Here is the error line displayed:
in Controller.php line 107
2.at Controller->__call('validate', array(object(Request), array('action' => 'required', 'name' => 'required'))) in NiceActionController.php line 31
3.at NiceActionController->validate(object(Request), array('action' => 'required', 'name' => 'required')) in NiceActionController.php line 31
4.at NiceActionController->postNiceAction(object(Request))
5.at call_user_func_array(array(object(NiceActionController), 'postNiceAction'), array(object(Request))) in Controller.php line 80
6.at Controller->callAction('postNiceAction', array(object(Request))) in ControllerDispatcher.php line 146
7.at ControllerDispatcher->call(object(NiceActionController), object(Route), 'postNiceAction') in ControllerDispatcher.php line 94
8.at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
9.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
10.at Pipeline->Illuminate\Routing\{closure}(object(Request))
11.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
12.at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
13.at ControllerDispatcher->callWithinStack(object(NiceActionController), object(Route), object(Request), 'postNiceAction') in ControllerDispatcher.php line 54
14.at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\NiceActionController', 'postNiceAction') in Route.php line 174
15.at Route->runController(object(Request)) in Route.php line 140
16.at Route->run(object(Request)) in Router.php line 724
17.at Router->Illuminate\Routing\{closure}(object(Request))
18.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
19.at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
20.at VerifyCsrfToken->handle(object(Request), object(Closure))
21.at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
22.at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
23.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
24.at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
25.at ShareErrorsFromSession->handle(object(Request), object(Closure))
26.at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
27.at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
28.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
29.at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 62
30.at StartSession->handle(object(Request), object(Closure))
31.at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
32.at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
33.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
34.at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
35.at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
36.at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
37.at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
38.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
39.at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
40.at EncryptCookies->handle(object(Request), object(Closure))
41.at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
42.at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
43.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
44.at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
45.at VerifyCsrfToken->handle(object(Request), object(Closure))
46.at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
47.at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
48.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
49.at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
50.at ShareErrorsFromSession->handle(object(Request), object(Closure))
51.at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
52.at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
53.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
54.at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 62
55.at StartSession->handle(object(Request), object(Closure))
56.at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
57.at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
58.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
59.at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
60.at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
61.at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
62.at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
63.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
64.at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
65.at EncryptCookies->handle(object(Request), object(Closure))
66.at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
67.at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
68.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
69.at Pipeline->Illuminate\Routing\{closure}(object(Request))
70.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
71.at Pipeline->then(object(Closure)) in Router.php line 726
72.at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
73.at Router->dispatchToRoute(object(Request)) in Router.php line 675
74.at Router->dispatch(object(Request)) in Kernel.php line 246
75.at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
76.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
77.at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
78.at CheckForMaintenanceMode->handle(object(Request), object(Closure))
79.at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
80.at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
81.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
82.at Pipeline->Illuminate\Routing\{closure}(object(Request))
83.at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
84.at Pipeline->then(object(Closure)) in Kernel.php line 132
85.at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
86.at Kernel->handle(object(Request)) in index.php line 54
My route code:
<?php
Route::group(['middleware' => ['web']], function(){
Route::get('/', function () {
return view('home');
})->name('home');
Route::group(['prefix'=>'do'], function(){
Route::get('/{action}/{name?}', [
'uses' => 'NiceActionController#getNiceAction',
'as' => 'niceaction' //router name same as ->name('routername')
]);
Route::post('/', [
'uses' => 'NiceActionController#postNiceAction',
'as' => 'benice'
]);
});
});
My Controller code is given below:
<?php
namespace App\Http\Controllers;
use Illuminate\Routing\Controller;
use \Illuminate\Http\Request;
class NiceActionController extends Controller
{
public function getNiceAction($action, $name=null)
{
return view('actions.'.$action, ['name' => $name]);
}
public function postNiceAction(Request $request)
{
$this->validate($request, [
'action' => 'required',
'name' =>'required'
]);
return view('actions.nice', ['action'=>$request['action'],'name'=>$this->transformName($request['name'])]);
}
private function transformName($name)
{
$prefix='KING';
return $prefix.strtoupper($name);
}
}
My base main controller "controller" has following code:
<?php
namespace App\Http\Controllers;
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;
class Controller extends BaseController
{
use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;
}
Am i missing anything????
You need to extend the App\Http\Controllers\Controller class which uses the necessary ValidatesRequests trait that implements the required validate method.
So in your NiceActionController class just remove this line:
use Illuminate\Routing\Controller;
That way this line:
class NiceActionController extends Controller
Will extend the proper Controller class from the same namespace (more precisely App\Http\Controllers\Controller), which includes the necessary traits and which already extends that Illuminate\Routing\Controller class (aliased as BaseController).
To display errors, simply remove the line below and the closing )}
Route::group(['middleware' => ['web']], function(){
As of 5.2, routes.php is by default already called in the context of a ['middleware'=>'web'] by RouteServiceProvider.
// But in routes.php default generation of auth routes, the Route::group call is still happening by default - so if you delete that Route::group
// declaration from routes.php the application then correctly shows errors.

Call to undefined method Illuminate\Database\Query\Builder::save()- Laravel 5

I can't figure it out. I think it happens when it hits my activateAccount controller function. Inside that function I call on account_activated function where user gets saved. Plus I'm getting the first instance of the user object so I don't what's wrong.
This is the controller function
public function activateAccount(Request $request, User $user, $key) {
$registered = $request->session()->get('registered');
if (isset($registered)) {
$request->session()->forget('registered');
if ($user->account_activated($key)) {
// TODO
$referral = Referrals::where('activation_key', $key);
if (!empty($referral)) {
$referral->validate = 1;
$referral->save();
}
return redirect('/login')->with('success', "Your account has been activated. You many login!");
} else {
return redirect('/not-active');
}
} else {
return redirect('/');
}
}
account_activated function inside the User model
public function account_activated($key){
$user = User::where('activate_key', $key)->first();
$user->activate = 1;
$user->save();
return true;
}
This is the error msg
BadMethodCallException in Builder.php line 2047:
Call to undefined method Illuminate\Database\Query\Builder::save()
in Builder.php line 2047
at Builder->__call('save', array())
at Builder->save()
at call_user_func_array(array(object(Builder), 'save'), array()) in Builder.php line 943
at Builder->__call('save', array()) in RegisterController.php line 155
at Builder->save() in RegisterController.php line 155
at RegisterController->activateAccount(object(Request), object(User), 'OjkTKaLIVAaRhveYRZz9rC1uAuPjUc6fk4BeZhUM')
at call_user_func_array(array(object(RegisterController), 'activateAccount'), array(object(Request), object(User), 'key' => 'OjkTKaLIVAaRhveYRZz9rC1uAuPjUc6fk4BeZhUM')) in Controller.php line 256
at Controller->callAction('activateAccount', array(object(Request), object(User), 'key' => 'OjkTKaLIVAaRhveYRZz9rC1uAuPjUc6fk4BeZhUM')) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(RegisterController), object(Route), 'activateAccount') 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))
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(RegisterController), object(Route), object(Request), 'activateAccount') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\RegisterController', 'activateAccount') in Route.php line 201
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(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 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
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
The error that you are getting isn't coming from the function that you call, but within the activateAccount function itself.
In particular these lines here:
$referral = Referrals::where('activation_key', $key);
if (!empty($referral)) {
$referral->validate = 1;
$referral->save();
}
You need to fetch the model after giving your where clause. By the looks of it you already know how to do this, but for completeness sake you just need to add in a ->first():
$referral = Referrals::where('activation_key', $key)->first();
if (!empty($referral)) {
$referral->validate = 1;
$referral->save();
}

Categories