QueryException in Laravel 5 when executing Model::create - php

I a newbie to Laravel. In my project there is a Model called Student and a table in MySQL student.
When I am trying to insert some values to the database using Student::create , it gives me the following errors.
The database table exists and I retrieved some values from another table before.
My Insert Code in the Controller:
Student::create([
'name' => Input::get('student_name'),
'email' => Input::get('student_email',
'contact' => Input::get('student_tel'),
'reg_id' => Input::get('registration_no'),
'password' => Hash::make(Input::get('password'))
]);
My Model Class:
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Student extends Model {
protected $table = 'student';
protected $fillable = ['name', 'email', 'contact', 'username', 'password'];
}
Complete Error for QueryException
QueryException in Connection.php line 620: SQLSTATE[42S02]: Base table
or view not found: 1146 Table 'msc_project.tablename' doesn't exist
(SQL: select count(*) as aggregate from tablename where
registration_no = asgfsag)
``**in Connection.php line 620
at Connection->runQueryCallback('select count(*) as aggregate from `tablename` where `registration_no` = ?', array('ffhfdh'), object(Closure)) in Connection.php line 576
at Connection->run('select count(*) as aggregate from `tablename` where `registration_no` = ?', array('ffhfdh'), object(Closure)) in Connection.php line 293
at Connection->select('select count(*) as aggregate from `tablename` where `registration_no` = ?', array('ffhfdh'), true) in Builder.php line 1377
at Builder->runSelect() in Builder.php line 1367
at Builder->getFresh(array('*')) in Builder.php line 1354
at Builder->get(array('*')) in Builder.php line 1636
at Builder->aggregate('count', array('*')) in Builder.php line 1574
at Builder->count() in DatabasePresenceVerifier.php line 57
at DatabasePresenceVerifier->getCount('tablename', 'registration_no', 'ffhfdh', null, null, array()) in Validator.php line 1057
at Validator->validateUnique('registration_no', 'ffhfdh', array('tablename'), object(Validator)) in Validator.php line 372
at Validator->validate('registration_no', 'unique:tablename') in Validator.php line 325
at Validator->passes() in Validator.php line 347
at Validator->fails() in StudentController.php line 56
at StudentController->doRegistration()
at call_user_func_array(array(object(StudentController), 'doRegistration'), array()) in Controller.php line 246
at Controller->callAction('doRegistration', array()) in ControllerDispatcher.php line 162
at ControllerDispatcher->call(object(StudentController), object(Route), 'doRegistration') in ControllerDispatcher.php line 107
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 108
at ControllerDispatcher->callWithinStack(object(StudentController), object(Route), object(Request), 'doRegistration') in ControllerDispatcher.php line 67
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\StudentController', 'doRegistration') in Route.php line 198
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 131
at Route->run(object(Request)) in Router.php line 691
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Router.php line 693
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 660
at Router->dispatchToRoute(object(Request)) in Router.php line 618
at Router->dispatch(object(Request)) in Kernel.php line 210
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 111
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
at require_once('/home/pranavaghanan/Documents/GitHub Projects/MScApp/public/index.php') in server.php line 21
Complete Error List for PDOException
PDOException in Connection.php line 288: SQLSTATE[42S02]: Base table
or view not found: 1146 Table 'msc_project.tablename' doesn't exist
in Connection.php line 288
at PDO->prepare('select count(*) as aggregate from `tablename` where `registration_no` = ?') in Connection.php line 288
at Connection->Illuminate\Database\{closure}(object(MySqlConnection), 'select count(*) as aggregate from `tablename` where `registration_no` = ?', array('ffhfdh')) in Connection.php line 612
at Connection->runQueryCallback('select count(*) as aggregate from `tablename` where `registration_no` = ?', array('ffhfdh'), object(Closure)) in Connection.php line 576
at Connection->run('select count(*) as aggregate from `tablename` where `registration_no` = ?', array('ffhfdh'), object(Closure)) in Connection.php line 293
at Connection->select('select count(*) as aggregate from `tablename` where `registration_no` = ?', array('ffhfdh'), true) in Builder.php line 1377
at Builder->runSelect() in Builder.php line 1367
at Builder->getFresh(array('*')) in Builder.php line 1354
at Builder->get(array('*')) in Builder.php line 1636
at Builder->aggregate('count', array('*')) in Builder.php line 1574
at Builder->count() in DatabasePresenceVerifier.php line 57
at DatabasePresenceVerifier->getCount('tablename', 'registration_no', 'ffhfdh', null, null, array()) in Validator.php line 1057
at Validator->validateUnique('registration_no', 'ffhfdh', array('tablename'), object(Validator)) in Validator.php line 372
at Validator->validate('registration_no', 'unique:tablename') in Validator.php line 325
at Validator->passes() in Validator.php line 347
at Validator->fails() in StudentController.php line 56
at StudentController->doRegistration()
at call_user_func_array(array(object(StudentController), 'doRegistration'), array()) in Controller.php line 246
at Controller->callAction('doRegistration', array()) in ControllerDispatcher.php line 162
at ControllerDispatcher->call(object(StudentController), object(Route), 'doRegistration') in ControllerDispatcher.php line 107
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 108
at ControllerDispatcher->callWithinStack(object(StudentController), object(Route), object(Request), 'doRegistration') in ControllerDispatcher.php line 67
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\StudentController', 'doRegistration') in Route.php line 198
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 131
at Route->run(object(Request)) in Router.php line 691
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Router.php line 693
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 660
at Router->dispatchToRoute(object(Request)) in Router.php line 618
at Router->dispatch(object(Request)) in Kernel.php line 210
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 111
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
at require_once('/home/pranavaghanan/Documents/GitHub Projects/MScApp/public/index.php') in server.php line 21
UPDATE :
I just found out that when comment out the code which is for Validation, the data goes into the database. Any idea why this line is causing the error?
$validator = \Validator::make($postedData, $rules, $messages);
if ($validator->fails()) {
return Redirect::to('registration')->withInput()->withErrors($validator);
}
If I don't use \Validator it doesn't accept the class either.

Related

Trying to get property of non-object laravel bogardo/mailgun/src/http/response

This error appears when I try to send email with mailgun package for laravel (bogardo/mailgun).
Route:
Route::post('mail-list/send/{type}/{id}', ['uses' => 'MailingList\MailingListController#sendSiteNews', 'as' => 'mail-list.send']);
Controller MailingListController
use Bogardo\Mailgun\Mail\Message;
use Mailgun;
Controller method:
public function sendSiteNews($type, $id) {
$data = [];
Mailgun::send('email.batch-news', $data, function (Message $message) {
$message->to('foo#example.com', 'John Smith')->subject('Welcome!');
});
];
At first I've tried batch sending. Result was the same. After that I've tried to send simple message like above.
view email.batch-news contains only text with h1 tag.
Error message:
ErrorException in Response.php line 35:
Trying to get property of non-object
in Response.php line 35
at HandleExceptions->handleError(8, 'Trying to get property of non-object', 'D:\\wamp\\www\\asiacrochet\\vendor\\bogardo\\mailgun\\src\\Http\\Response.php', 35, array('response' => object(stdClass))) in Response.php line 35
at Response->__construct(object(stdClass)) in Mailer.php line 68
at Mailer->send('email.batch-news', array(), object(Closure)) in Service.php line 59
at Service->send('email.batch-news', array(), object(Closure)) in Facade.php line 221
at Facade::__callStatic('send', array('email.batch-news', array(), object(Closure))) in MailingListController.php line 67
at MailingListController->sendSiteNews('Lesson', '10')
at call_user_func_array(array(object(MailingListController), 'sendSiteNews'), array('Lesson', '10')) in Controller.php line 55
at Controller->callAction('sendSiteNews', array('Lesson', '10')) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(MailingListController), 'sendSiteNews') in Route.php line 203
at Route->runController() in Route.php line 160
at Route->run() in Router.php line 559
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in HasRole.php line 24
at HasRole->handle(object(Request), object(Closure), 'administrator') in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Authenticate.php line 43
at Authenticate->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Router.php line 561
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 520
at Router->dispatchToRoute(object(Request)) in Router.php line 498
at Router->dispatch(object(Request)) in Kernel.php line 174
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 47
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 53
That is method of package:
public function __construct(stdClass $response)
{dd($response->http_response_body);
$this->status = $response->http_response_code;
$this->message = $response->http_response_body->message;
$this->id = property_exists($response->http_response_body, 'id') ? $response->http_response_body->id : '';
$this->data = null;
}
dd($response->http_response_body);
gives only that string value "Mailgun Magnificent API".
So that is the problem.
Check your send-domain "email.batch-news". If this is incorrect mailgun, does identify the API method you are calling.

Laravel unique validation class Class Dokter does not exist

i have some problem with unique validation laravel
<?php
namespace Amodules\Hmastermedis\Http\Controllers;
use Illuminate\Http\Request;
use Amodules\Hmastermedis\Models\Dokter;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Theme;
use Amodules\Hmastermedis\Models\Spesialisasi;
use Yajra\Datatables\Facades\Datatables;
use DB;
use Session;
use validate;
class DokterController extends Controller
{
public function store(Request $request)
{
$this->validate($request, [
'dr_cd' => 'required|unique:Dokter',
'dr_nm' => 'required',
]);
$dokter = new Dokter();
$dokter->dr_cd=$request->dr_cd;
$dokter->dr_nm=$request->dr_nm;
$dokter->spesialis_cd=$request->spesialis_cd;
$dokter->save();
Session::flash('dokter', 'Dokter berhasil di tambahkan');
return redirect('hmastermedis/dokter');
}
}
and this my model
<?php
namespace Amodules\Hmastermedis\Models;
use Illuminate\Database\Eloquent\Model;
/**
*
*/
class Dokter extends Model
{
public $primarykey = 'dr_cd';
public $incrementing = false;
protected $fillable = ['dr_cd','dr_cm','spesialis_cd','paramedis_tp'];
protected $table = 'trx_dokter';
public $timestamps = false;
public function spesialisasi()
{
return $this->hasOne('Amodules\Hmastermedis\Models\Spesialisasi','spesialis_cd','spesialis_cd');
}
}
but when i run my code, class dokter does not exist
Whoops, looks like something went wrong.
1/1 ReflectionException in IlluminateRegistry.php line 334: Class Dokter does not exist
in IlluminateRegistry.php line 334
at ReflectionClass->__construct('Dokter') in IlluminateRegistry.php line 334
at IlluminateRegistry->getManagerForClass('Dokter') in DoctrinePresenceVerifier.php line 123
at DoctrinePresenceVerifier->getEntityManager('Dokter') in DoctrinePresenceVerifier.php line 92
at DoctrinePresenceVerifier->select('Dokter') in DoctrinePresenceVerifier.php line 45
at DoctrinePresenceVerifier->getCount('Dokter', 'dr_cd', 'df', null, null, array()) in Validator.php line 1426
at Validator->validateUnique('dr_cd', 'df', array('Dokter'), object(Validator)) in Validator.php line 545
at Validator->validateAttribute('dr_cd', 'unique:Dokter') in Validator.php line 461
at Validator->passes() in Validator.php line 486
at Validator->fails() in ValidatesRequests.php line 54
at Controller->validate(object(Request), array('dr_cd' => 'required|unique:Dokter', 'dr_nm' => 'required')) in DokterController.php line 60
at DokterController->store(object(Request))
at call_user_func_array(array(object(DokterController), 'store'), array(object(Request))) in Controller.php line 55
at Controller->callAction('store', array(object(Request))) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(DokterController), 'store') in Route.php line 190
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 642
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
at VerifyCsrfToken->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 ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->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 StartSession.php line 64
at StartSession->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 AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->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 EncryptCookies.php line 59
at EncryptCookies->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 Router.php line 644
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 618
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
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 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54
at require_once('D:\xampp\htdocs\amteklab\AMHES\public\index.php') in server.php line 21
thanks four your help
If your model class was created after the controller you are calling it from you need to run composer dump-autoload so that the Dokter is added to the project's autoload_classmap.php

Exceptions at renaming a column in Laravel 5.1 DB

i just did a migration in Laravel. I noticed that in the users table there are several columns: id, name, email and so on. I changed the the column named "name" to "username" and i put it as a unique column. Now when I start my app and try to register i get 2 exeptions: QueryExpetion and PDOExeption. I thought that I should change something in the Builder.php bou there is no such thing in there. These are the error I got. What do I need to change?!
QueryException in Connection.php line 651: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'where clause' (SQL: select count(*) as aggregate from `users` where `name` = kosach)
in Connection.php line 651
at Connection->runQueryCallback('select count(*) as aggregate from `users` where `name` = ?', array('kosach'), object(Closure)) in Connection.php line 611
at Connection->run('select count(*) as aggregate from `users` where `name` = ?', array('kosach'), object(Closure)) in Connection.php line 324
at Connection->select('select count(*) as aggregate from `users` where `name` = ?', array('kosach'), true) in Builder.php line 1406
at Builder->runSelect() in Builder.php line 1383
at Builder->get(array('*')) in Builder.php line 1718
at Builder->aggregate('count', array('*')) in Builder.php line 1638
at Builder->count() in DatabasePresenceVerifier.php line 57
at DatabasePresenceVerifier->getCount('users', 'name', 'kosach', null, null, array()) in Validator.php line 1070
at Validator->validateUnique('name', 'kosach', array('users'), object(Validator)) in Validator.php line 362
at Validator->validate('name', 'unique:users') in Validator.php line 314
at Validator->passes() in Validator.php line 335
at Validator->fails() in RegistersUsers.php line 32
at AuthController->postRegister(object(Request))
at call_user_func_array(array(object(AuthController), 'postRegister'), array(object(Request))) in Controller.php line 256
at Controller->callAction('postRegister', array(object(Request))) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(AuthController), object(Route), 'postRegister') 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 45
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(AuthController), object(Route), object(Request), 'postRegister') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\Auth\AuthController', 'postRegister') 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(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
1/2 PDOException in Connection.php line 319: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'where clause'
in Connection.php line 319
at PDO->prepare('select count(*) as aggregate from `users` where `name` = ?') in Connection.php line 319
at Connection->Illuminate\Database\{closure}(object(MySqlConnection), 'select count(*) as aggregate from `users` where `name` = ?', array('kosach')) in Connection.php line 644
at Connection->runQueryCallback('select count(*) as aggregate from `users` where `name` = ?', array('kosach'), object(Closure)) in Connection.php line 611
at Connection->run('select count(*) as aggregate from `users` where `name` = ?', array('kosach'), object(Closure)) in Connection.php line 324
at Connection->select('select count(*) as aggregate from `users` where `name` = ?', array('kosach'), true) in Builder.php line 1406
at Builder->runSelect() in Builder.php line 1383
at Builder->get(array('*')) in Builder.php line 1718
at Builder->aggregate('count', array('*')) in Builder.php line 1638
at Builder->count() in DatabasePresenceVerifier.php line 57
at DatabasePresenceVerifier->getCount('users', 'name', 'kosach', null, null, array()) in Validator.php line 1070
at Validator->validateUnique('name', 'kosach', array('users'), object(Validator)) in Validator.php line 362
at Validator->validate('name', 'unique:users') in Validator.php line 314
at Validator->passes() in Validator.php line 335
at Validator->fails() in RegistersUsers.php line 32
at AuthController->postRegister(object(Request))
at call_user_func_array(array(object(AuthController), 'postRegister'), array(object(Request))) in Controller.php line 256
at Controller->callAction('postRegister', array(object(Request))) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(AuthController), object(Route), 'postRegister') 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 45
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(AuthController), object(Route), object(Request), 'postRegister') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\Auth\AuthController', 'postRegister') 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(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 default AuthController uses name for creating the user in the create method.
Change this line's key to username.
Well even though you’ve changed the name of the column in your database, it looks like somewhere in your code you’re still referencing name.

laravel 5 belongsToMany Error after composer update

I am getting error after composer update
QueryException in Connection.php line 636:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'war_id' in 'where clause'
I have 3 tables in many to many relationship
wars table
id - int pk
locations table
id - int pk
war_locations table
id - int pk
war_id int
location_id int
war_locations table is pivot table.
I have declared relation ship in model
War.php
public function locations()
{
return $this->belongsToMany('App\Models\Location', 'war_locations', 'war_id', 'location_id');
}
But when i try to get location of a war then it fails.
$wars = War::with('locations')->where('status',1)->get();
It was working before composer update
I dont know why it is trying to find war_id in pivot table.
Complete exception:
`PDOException in Connection.php line 310:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'war_id' in 'where clause'
in Connection.php line 310
at PDO->prepare('select * from `wc_locations` where `war_id` = ?') in Connection.php line 310
at Connection->Illuminate\Database\{closure}(object(MySqlConnection), 'select * from `wc_locations` where `war_id` = ?', array('2')) in Connection.php line 629
at Connection->runQueryCallback('select * from `wc_locations` where `war_id` = ?', array('2'), object(Closure)) in Connection.php line 596
at Connection->run('select * from `wc_locations` where `war_id` = ?', array('2'), object(Closure)) in Connection.php line 315
at Connection->select('select * from `wc_locations` where `war_id` = ?', array('2'), true) in Builder.php line 1389
at Builder->runSelect() in Builder.php line 1379
at Builder->getFresh(array('*')) in Builder.php line 1364
at Builder->get(array('*')) in Builder.php line 409
at Builder->getModels() in BelongsToMany.php line 176
at BelongsToMany->get() in BelongsToMany.php line 99
at BelongsToMany->getResults() in Model.php line 2699
at Model->getRelationshipFromMethod('locations') in Model.php line 2665
at Model->getRelationValue('locations') in Model.php line 2607
at Model->getAttribute('locations') in Model.php line 3325
at Model->__get('locations') in War.php line 102
at War->getLocationListAttribute(null) in Model.php line 2722
at Model->mutateAttribute('location_list', null) in Model.php line 2734
at Model->mutateAttributeForArray('location_list', null) in Model.php line 2494
at Model->attributesToArray() in Model.php line 2434
at Model->toArray() in Collection.php line 902
at Collection->Illuminate\Support\{closure}(object(War))
at array_map(object(Closure), array(object(War), object(War), object(War), object(War), object(War), object(War))) in Collection.php line 904
at Collection->toArray() in Collection.php line 914
at Collection->jsonSerialize()
at json_encode(object(Collection)) in 6823600b52dddc7dc45dcf9b454ab6d0 line 559
at include('/home/aditya/public_html/warcircle/storage/framework/views/6823600b52dddc7dc45dcf9b454ab6d0') in PhpEngine.php line 42
at PhpEngine->evaluatePath('/home/aditya/public_html/warcircle/storage/framework/views/6823600b52dddc7dc45dcf9b454ab6d0', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'wars' => object(Collection), 'user' => null, 'trendingWars' => array(object(War), object(War)), 'topWars' => object(Collection))) in CompilerEngine.php line 58
at CompilerEngine->get('/home/aditya/public_html/warcircle/resources/views/site/home/index.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'wars' => object(Collection), 'user' => null, 'trendingWars' => array(object(War), object(War)), 'topWars' => object(Collection))) in View.php line 138
at View->getContents() in View.php line 107
at View->renderContents() in View.php line 81
at View->render() in Response.php line 51
at Response->setContent(object(View)) in Response.php line 202
at Response->__construct(object(View)) in Router.php line 1225
at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 113
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(HomeController), object(Route), object(Request), 'index') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\Site\HomeController', 'index') 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`
It looks like the keys in your relationship are in the wrong order. Try swapping war_id and location_id like so:
public function locations()
{
return $this->belongsToMany('App\Models\Location', 'war_locations', 'location_id', 'war_id');
}

Laravel 5 Routing Issue - Bad Method Call Exception

I'm attempting to simply send a 'PUT' request to one of my routes (which is called as a resource in the route file), yet I recieve this traceback as the response.
Whoops, looks like something went wrong.
1/1 BadMethodCallException in Controller.php line 273: Method [show] does not exist.
in Controller.php line 273
at Controller->__call('show', array('1'))
at AccountControllerV2->show('1')
at call_user_func_array(array(object(AccountControllerV2), 'show'), array('account' => '1')) in Controller.php line 246
at Controller->callAction('show', array('account' => '1')) in ControllerDispatcher.php line 162
at ControllerDispatcher->call(object(AccountControllerV2), object(Route), 'show') in ControllerDispatcher.php line 107
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 108
at ControllerDispatcher->callWithinStack(object(AccountControllerV2), object(Route), object(Request), 'show') in ControllerDispatcher.php line 67
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\API\V2\AccountControllerV2', 'show') in Route.php line 198
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 131
at Route->run(object(Request)) in Router.php line 692
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Authenticate.php line 47
at Authenticate->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Router.php line 694
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 661
at Router->dispatchToRoute(object(Request)) in Router.php line 619
at Router->dispatch(object(Request)) in Kernel.php line 214
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in HttpsProtocol.php line 15
at HttpsProtocol->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 115
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
I cannot for the life of me figure out why this is happening.
Here is a code snippet from the Controller itself (which extends BaseController):
/**
* Update the currently logged User in storage.
*
* #return Response 201
* #return jsonArray account
* #return string message
*/
public function update($account_id) {
$input = Input::all();
$message = 'Account Successfully Updated';
$user = Auth::User();
And here is the Route declaration:
Route::group(array('prefix' => 'api/v2', 'namespace' => 'API\V2', 'middleware' => 'auth'), function()
{
Route::resource('challenges', 'ChallengeControllerV2', ['only'=> ['index','store','update','destroy']]);
Route::resource('groups', 'GroupControllerV2');
Route::resource('account', 'AccountControllerV2');
The call is being made to the correct path. Any ideas why I'm getting what seems to be an illogical response? There is no additional middleware/filters attached to the controller than what is shown.
It turns out that in Laravel 5 if you do not specify the resources available on a Route it will assume that they are all there (unlike in Laravel 4 where it checks to see what resources are available in all controllers). So I had to change the line like so.
Route::resource('account', 'AccountControllerV2', ['only'=> ['index','update','destroy']]);

Categories