I try to learn Doctrine2 now so I created a trivial Entity (actually I got it from tutorial):
<?php
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
*/
class Product {
/**
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
* #ORM\Column(type="integer")
*/
protected $id;
/**
* #ORM\Column(type="string")
*/
protected $name;
public function getId() {
return $this->id;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name;
return $this;
}
}
I also created an action to create and persist such product:
public function createProductAction() {
$em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
$em->getConnection()
->getConfiguration()
->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
$product = new Product();
$product->setName("Test product");
$em->persist($product);
$em->flush();
echo "Created product with ID ".$product->getId();
}
Of course before test I've ran a command to create db scheme (and checked that it's actually created). Simillar code for User runs smoothly but this action reports following:
"START TRANSACTION" INSERT INTO Product (name) VALUES (?)
array (size=1)
1 => null
array (size=1)
1 => string 'string' (length=6)
"ROLLBACK"
What's wrong?? Is there anyway to debug it somehow?? :|
Related
I am using ZF2 version-2.5.0 and doctrine version- ~2.5
I have three entities namely event, ranking and country as follows :
<?php
namespace SampleProject\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use SampleProject\Entity\Country;
use SampleProject\Entity\Ranking;
class Event
{
/**
*
* #ORM\Id
* #ORM\Column(name="eventID", type="integer", precision=0, nullable=false)
* #var int $eventID
*/
protected $eventID;
/**
* #ORM\Column(name="name", type="string", length=50, precision=0, nullable=false)
* #var string $name
*/
protected $name;
/**
* #ORM\OneToMany(targetEntity="SampleProject\Entity\Ranking", mappedBy="event")
* #var ArrayCollection $rankings
*/
protected $rankings;
/**
* #ORM\ManyToOne(targetEntity="SampleProject\Entity\Country", inversedBy="events", fetch="EXTRA_LAZY", cascade={"detach"})
* #ORM\JoinColumn(name="countryIso", referencedColumnName="countryIso", nullable=false)
* #var \SampleProject\Entity\Country $country
*/
protected $country;
/**
* Initializes doctrine collections, called from constructor in entity class
*/
protected function initializeCollections()
{
$this->rankings = new ArrayCollection();
}
public function setEventID($eventID)
{
$this->eventID = (int)$eventID;
return $this;
}
public function getEventID()
{
return $this->eventID;
}
public function setName($name)
{
$this->name = (string)$name;
return $this;
}
public function getName()
{
return $this->name;
}
public function setCountry(Country $country)
{
$this->country = $country;
return $this;
}
public function getCountry()
{
return $this->country;
}
public function addRanking(Ranking $ranking)
{
$this->rankings[] = $ranking;
return $this;
}
public function getRankings()
{
return $this->rankings;
}
}
?>
<?php
namespace SampleProject\Country;
use SampleProject\Entity\Event;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
class Country
{
/**
*
* #ORM\Id
* #ORM\Column(name="countryIso", type="string", length=3, precision=0, nullable=false)
* #var string $countryIso
*/
protected $countryIso;
/**
* #ORM\Column(name="name", type="string", length=50, precision=0, nullable=false)
* #var string $name
*/
protected $name;
/**
* #ORM\OneToMany(targetEntity="SampleProject\Entity\Event", mappedBy="country", fetch="EXTRA_LAZY")
* #var ArrayCollection $events
*/
protected $events;
/**
* Initializes doctrine collections, called from constructor in entity class
*/
protected function initializeCollections()
{
$this->events = new ArrayCollection();
}
public function setCountryIso($countryIso)
{
$this->countryIso = (string) $countryIso;
return $this;
}
public function getCountryIso()
{
return $this->countryIso;
}
public function setName($name)
{
$this->name = (string) $name;
return $this;
}
public function getName()
{
return $this->name;
}
public function addEvent(Event $event)
{
$this->events->add($event);
return $this;
}
public function getEvents()
{
return $this->events;
}
}
?>
<?php
namespace SampleProject\Ranking;
use Doctrine\ORM\Mapping as ORM;
use SampleProject\Entity\Event;
class Ranking
{
/**
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
* #ORM\Column(type="integer", precision=0, nullable=false)
* #var int $rankingID
*/
protected $rankingID;
/**
* #ORM\Column(name="rank", type="integer", precision=0, nullable=true)
* #var int $rank
*/
protected $rank;
/**
* #ORM\ManyToOne(targetEntity="SampleProject\Entity\Event", inversedBy="rankings", fetch="LAZY")
* #ORM\JoinColumn(name="eventID", referencedColumnName="eventID", nullable=false)
* #var \SampleProject\Entity\Event $event
*/
protected $event;
/**
* #ORM\Column(name="locale", type="string", length=5, precision=0, nullable=true)
* #var string $locale
*/
protected $locale;
public function getRankingID()
{
return $this->rankingID;
}
public function setRank($rank)
{
$this->rank = (int) $rank;
return $this;
}
public function getRank()
{
return $this->rank;
}
public function setEvent(Event $event)
{
$this->event = $event;
return $this;
}
public function getEvent()
{
return $this->event;
}
public function getLocale()
{
return $this->locale;
}
public function setLocale($locale)
{
$this->locale = $locale;
}
}
?>
One event belongs to one country and one country can have multiple events.
One event have multiple rankings depending on locale i.e. (en, nl etc.).
I am using ZF2 and doctrine to get listing of events order by rankings in ascending order.
Internally it executes following query to show events listing:
SELECT a0_.name AS name_3, a0_.countryIso AS countryIso_37, COALESCE(a1_.rank, 99999) AS sclr_34
FROM Event a0_
LEFT JOIN Ranking a1_ ON a0_.eventID = a1_.eventID AND (a1_.locale = 'en' OR a1_.locale IS NULL)
INNER JOIN Country a2_ ON a0_.countryIso = a2_.countryIso
GROUP BY a0_.eventID
ORDER BY sclr_34 ASC, a0_.name ASC
So the result is something like as follows :
event1 BEL 1
event2 AUS 2
event3 AUS 3
event4 AUS 4
event5 NLD 5
event6 NLD 6
event7 ESP 7
But now, I want to display events per event per country. So the output will be like :
event1 BEL 1
event2 AUS 2
event5 NLD 5
event7 ESP 7
So, I believe query will be now like below :
SELECT * FROM (
SELECT a0_.name AS name_3, a0_.countryIso AS countryIso_37, COALESCE(a1_.rank, 99999) AS sclr_34
FROM Event a0_
LEFT JOIN Ranking a1_ ON a0_.eventID = a1_.eventID AND (a1_.locale = 'en' OR a1_.locale IS NULL)
INNER JOIN Country a2_ ON a0_.countryIso = a2_.countryIso
GROUP BY a0_.eventID
ORDER BY sclr_34 ASC, a0_.name ASC
) as t
GROUP BY t.countryIso_37 ORDER BY t.sclr_34 ASC limit 6;
But, with ZF2 and doctrine I am unable to prepare above query.
How can I achieve this using ZF2 and doctrine?
In a nutshell, I want to create a function that my query scopes can use across multiple models:
public function scopeNormaliseCurrency($query,$targetCurrency) {
return $query->normaliseCurrencyFields(
['cost_per_day','cost_per_week'],
$targetCurrency
);
}
I have got my logic working within this scope function no problem, but I want to make this code available to all my models, as there are multiple currency fields in different tables and I don't want to be replicating the code in each query scope - only specify the columns that need attention.
So, where would I make my function normaliseCurrencyFields? I have extended the Model class as well as used the newCollection keyword to extend Collection but both result in Call to undefined method Illuminate\Database\Query\Builder::normaliseCurrencyFields() errors.
I have looked into Global Scoping but this seems to be localised to a Model.
Am I along the right lines? Should I be targeting Eloquent specifically?
Create an abstract base model that extends eloquent then extend it with the classes you want to have access to it. I do this for searching functions, uuid creation, and class code functions. So that all of my saved models are required to have to certain attributes and access to my searching functions. For instance I created a static search function getobjectbyid(). So that when extended I can call it like so:
$user = User::getobjectbyid('habwiifnbrklsnbbd1938');
Thus way I know I am getting a user object back.
My base model:
<?php
/**
* Created by PhpStorm.
* User: amac
* Date: 6/5/17
* Time: 12:45 AM
*/
namespace App;
use Illuminate\Database\Eloquent\Model as Eloquent;
abstract class Model extends Eloquent
{
protected $guarded = [
'class_code',
'id'
];
public $primaryKey = 'id';
public $incrementing = false;
public function __construct($attributes = array()) {
parent::__construct($attributes); // Eloquent
$this->class_code = \App\Enums\EnumClassCode::getValueByKey(get_class($this));
$this->id = $this->class_code . uniqid();
return $this;
}
public static function getObjectById($id){
$class = get_called_class();
$results = $class::find($id);
return $results;
}
public static function getAllObjects(){
$class = get_called_class();
return $class::all();
}
my user model:
<?php
namespace App;
use Mockery\Exception;
use Illuminate\Support\Facades\Hash;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use App\Model as Model;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use Authenticatable;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'contact', 'username', 'email_address'
];
/**
* The column name of the "remember me" token.
*
* #var string
*/
protected $rememberTokenName = 'remember_token';
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'remember_token', 'active'
];
/**
* the attributes that should be guarded from Mass Assignment
*
* #var array
*/
protected $guarded = [
'created_at', 'updated_at', 'password_hash'
];
/**
* Define table to be used with this model. It defaults and assumes table names will have an s added to the end.
*for instance App\User table by default would be users
*/
protected $table = "user";
/**
* We have a non incrementing primary key
*
* #var bool
*/
public $incrementing = false;
/**
* relationships
*/
public function contact(){
// return $this->hasOne(Contact::class, 'id', 'contact_id');
return $this->hasOne(Contact::class);
}
public function customers(){
// return $this->hasOne(Contact::class, 'id', 'contact_id');
return $this->hasMany(Customer::class);
}
/**
* User constructor.
* #param array $attributes
*/
public function __construct($attributes = array()) {
parent::__construct($attributes); // Eloquent
// Your construct code.
$this->active = 1;
return $this;
}
/**
* #param $password string
* set user password_hash
* #return $this
*/
public function setPassword($password){
// TODO Password Validation
try{
$this->isActive();
$this->password_hash = Hash::make($password);
$this->save();
} catch(\Exception $e) {
dump($e->getMessage());
}
return $this;
}
/**
* Returns whether or not this use is active.
*
* #return bool
*/
public function isActive(){
if($this->active) {
return true;
} else {
Throw new Exception('This user is not active. Therefore you cannot change the password', 409);
}
}
public function getEmailUsername(){
$contact = Contact::getObjectById($this->contact_id);
$email = Email::getObjectById($contact->email_id);
return $email->username_prefix;
}
/**
* #return string
*
* getFullName
* returns concatenated first and last name of user.
*/
public function getFullName(){
return $this->first_name . ' ' . $this->last_name;
}
/**
* Get the name of the unique identifier for the user.
*
* #return string
*/
public function getAuthIdentifierName(){
return $this->getKeyName();
}
/**
* Get the unique identifier for the user.
*
* #return mixed
*/
public function getAuthIdentifier(){
return $this->{$this->getAuthIdentifierName()};
}
/**
* Get the password for the user.
*
* #return string
*/
public function getAuthPassword(){
return $this->password_hash;
}
/**
* Get the token value for the "remember me" session.
*
* #return string
*/
public function getRememberToken(){
if (! empty($this->getRememberTokenName())) {
return $this->{$this->getRememberTokenName()};
}
}
/**
* Set the token value for the "remember me" session.
*
* #param string $value
* #return void
*/
public function setRememberToken($value){
if (! empty($this->getRememberTokenName())) {
$this->{$this->getRememberTokenName()} = $value;
}
}
/**
* Get the column name for the "remember me" token.
*
* #return string
*/
public function getRememberTokenName(){
return $this->rememberTokenName;
}
/**
* Get the e-mail address where password reset links are sent.
*
* #return string
*/
public function getEmailForPasswordReset(){
}
/**
* Send the password reset notification.
*
* #param string $token
* #return void
*/
public function sendPasswordResetNotification($token){
}
public function validateAddress(){
}
}
a TestController:
public function test(){
$user = User::getObjectById('USR594079ca59746');
$customers = array();
foreach ($user->customers as $customer){
$contact = Contact::getObjectById($customer->contact_id);
$name = PersonName::getObjectById($contact->personname_id);
$c = new \stdClass();
$c->id = $customer->id;
$c->name = $name->preferred_name;
$customers[] = $c;
}
$response = response()->json($customers);
return $response;
}
Take note on how getObjectById is extended and available to my other classes that extend my base model. Also I do not have to specify in my user model an 'id' or 'class_code' and when my user model is constructed it calls the parent constructor which is the constructor on my base model that handles 'id' and 'class_code'.
I'm having trouble with logging users in, everything appears to be in the right place, I get no errors in the log, but users fail to log in, I am using the correct credentials that are in my database.
Please note I have a different set up to the normal one:
My table is called test_users
My model sits in a separate namespace called Test
Here's my code:
In config>auth I have set:
'model' => '\Test\User',
'table' => 'test_users',
Here is how I call the Auth:
public function logIn()
{
$input = Input::all();
$credentials = array('email' => $input['email'], 'password' => $input['password']);
$input['remember-me'] = isset($input['remember-me']) ? true : false;
if(Auth::attempt($credentials, $input['remember-me']))
{
$this->output['message'] = 'ok';
}
else
{
$this->output['message'] = 'fail';
}
return $this->output;
}
Here's my model:
<?php namespace Test;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
use Eloquent;
class User extends Eloquent implements UserInterface, RemindableInterface {
/**
* The database table used by the model.
*
* #var string
*/
protected $table = 'test_users';
/**
* The attributes excluded from the model's JSON form.
*
* #var array
*/
protected $hidden = array('password');
/**
* Get the unique identifier for the user.
*
* #return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* #return string
*/
public function getAuthPassword()
{
return $this->password;
}
/**
* Get the e-mail address where password reminders are sent.
*
* #return string
*/
public function getReminderEmail()
{
return $this->email;
}
}
Auth::attempt checks for a hashed password. It appears you might be trying to set them with plaintext. Try setting your passwords with Hash::make('password') if you aren't already.
I have 3 entities: Company, Industry, Category
I would like to create a form where the user can input the name of the company and then selects the Industry from a dropdown list. Every Industry has Categories. When user selects a Industry I want to populate the Category list. I've read following article: http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html#cookbook-form-events-submitted-data
I've created the form but when the ajax call is triggered I get following error:
Neither the property "categories" nor one of the methods "setCategories()", "__set()" or "__call()" exist and have public access in class "ebulucu\MainBundle\Entity\Company"
I'm on this now many days and just can't get it work. I hope somebody have some hints for me. I need a form with one input field for the company name, two dropdowns Industry and Category where Category depends on the selected Industry. Company has a ManyToMany relation to Category and Industry has a OneToMany relation too category. So far this is my code:
Edit:
I have tried the code with OneToMany instead ManyToMany relation between Company and Category.
That works fine. But what to do in case ManyToMany Relation? How to manage to load and set Categories?
my 3 entities:
class Company
{
/**
* #var integer
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #ORM\ManyToMany(targetEntity="Category", mappedBy="companies")
*/
private $categories;
/**
* Constructor
*/
public function __construct()
{
$this->categories = new \Doctrine\Common\Collections\ArrayCollection();
}
... setters and getters
class Industry
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=80)
* #Assert\NotBlank()
*/
private $name;
/**
* #var
*
* #ORM\OneToMany(targetEntity="Category",mappedBy="industry")
*/
private $categories;
public function __construct()
{
$this->categories = new ArrayCollection();
}
...setters and getters
class Category
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=80)
* #Assert\NotBlank()
*/
private $name;
/**
* #ORM\ManyToOne(targetEntity="Industry", inversedBy="categories");
* #ORM\JoinColumn(name="industry_id", referencedColumnName="id",nullable=false)
*/
private $industry;
/**
* #ORM\ManyToMany(targetEntity="Company", inversedBy="categories");
* #ORM\JoinTable(name="categories_companies")
*/
private $companies;
... setters and getters
My Company Form Class:
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use ebulucu\MainBundle\Entity\Industry;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
use Doctrine\ORM\EntityRepository;
class CompanyRegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name');
$builder->add('industry', 'entity', array(
'mapped' => false,
'class' => 'ebulucuMainBundle:Industry',
'property' => 'name',
'empty_value' => 'Choose industry',
));
$formModifier = function(FormInterface $form, $industry_id) {
if($industry_id) {
$form->add('categories', 'entity', array(
'class' => 'ebulucuMainBundle:Category',
'query_builder' => function(EntityRepository $er) use ($industry_id) {
$query = $er->createQueryBuilder('i')
->select(array('i'))
->where('i.industry_id = :industry_id')
->setParameter('industry_id', $industry_id)
->orderBy('i.name', 'ASC');
return $query;
},
'empty_value' => 'Choose category'
)
);
}
};
$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function(FormEvent $event) use ($formModifier) {
$formModifier($event->getForm(), null);
}
);
//** Checks for Industry that is submitted and adds categories based on industry selection **//
$builder->get('industry')->addEventListener(
FormEvents::POST_SUBMIT, function(FormEvent $event) use ($formModifier) {
$industry_id = $event->getData();
$formModifier($event->getForm()->getParent(), $industry_id);
}
);
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'ebulucu\MainBundle\Entity\Company',
));
}
public function getName()
{
return 'company';
}
}
The Controller:
use ebulucu\MainBundle\Entity\Company;
use ebulucu\MainBundle\Form\Type\CompanyRegistrationFormType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use ebulucu\MainBundle\Entity\Industry;
use ebulucu\MainBundle\Entity\Category;
use Symfony\Component\HttpFoundation\Request;
class MainController extends Controller
{
/**
* #Route("/", name="homepage")
* #Template()
*/
public function indexAction(Request $request)
{
$company = new Company();
$form = $this->createForm(new CompanyRegistrationFormType(), $company);
$form->handleRequest($request);
if ($form->isValid()) {
return $this->redirect($this->generateUrl('fos_user_security_login'));
}
return array(
'form' => $form->createView(),
);
}
/**
* #Route("/", name="loadIndustryCategories")
* #Template()
*/
public function loadIndustryCategories(Request $request)
{
$company = new Company();
$form = $this->createForm(new CompanyRegistrationFormType(), $company);
$form->handleRequest($request);
return array(
'form' => $form->createView(),
);
}
}
Twig Template with form and ajax call:
{% block content %}
<div>Homepage</div>
{{ form_start(form, {'attr': {'id': 'form_industry'}}) }}
{{ form_end(form) }}
{% endblock %}
{% block js%}
<script>
$('#company_industry').change( function() {
var postData = $("#form_industry").serializeArray();
var formURL = {{ path('loadIndustryCategories') }};
$.ajax(
{
url : formURL,
type: "POST",
data : postData,
success:function(data, textStatus, jqXHR)
{
//data: return data from server
},
error: function(jqXHR, textStatus, errorThrown)
{
//if fails
}
});
e.preventDefault(); //STOP default action
e.unbind(); //unbind. to stop multiple form submit.
});
</script>
{% endblock %}
Company:categories will be a collection of entities, not a singular entity, so it shouldn't have a setCategory method, otherwise you can inadvertently remove your whole collection. Instead you will have an addCategories, removeCategories and getCategories (this could be addCategorie and removeCategorie if doctrine generated due to its 'un-pluralization').
To fix, you need to change your categories form element to a type of collection instead of an entity in CompanyRegistrationFormType.
Just checking, should a company have one category or multiple? At the moment, your code seems to be somewhat a bit of both?
I can't Insert into this table and this drives me crazy
This is the error Msg I get
var_export does not handle circular references
open: /var/www/frameworks/Scout/vendor/laravel/framework/src/Illuminate/Database/Connection.php
* #param Exception $e
* #param string $query
* #param array $bindings
* #return void
*/
protected function handleQueryException(\Exception $e, $query, $bindings)
{
$bindings = var_export($bindings, true);
$message = $e->getMessage()." (SQL: {$query}) (Bindings: {$bindings})";
Here is my Full Mode
<?php
namespace Models;
use Illuminate\Database\Eloquent\Collection;
class Student extends \Eloquent
{
/**
* The database table used by the model.
*
* #var string
*/
protected $table = 'students';
/**
* The rules used to validate new Entry.
*
* #var array
*/
protected $newValidationRules = array(
'studentCode' => 'unique:students,code|numeric|required',
'studentName' => 'required|min:2',
'dateOfBirth' => 'date',
'mobile' => 'numeric'
);
/**
* Relation with sessions (Many To Many Relation)
* We added with Created_at to the Pivot table as it indicates the attendance time
*/
public function sessions()
{
return $this->belongsToMany('Models\Session', 'student_session')->withPivot('created_at')->orderBy('created_at', 'ASC');
}
/**
* Get Student Subjects depending on attendance,
*/
public function subjects()
{
$sessions = $this->sessions()->groupBy('subject_id')->get();
$subjects = new Collection();
foreach ($sessions as $session) {
$subject = $session->subject;
$subject->setRelation('student', $this);
$subjects->add($subject);
}
return $subjects;
}
/**
* Insert New Subject
* #return Boolean
*/
public function insertNew()
{
$this->validator = \Validator::make(\Input::all(), $this->newValidationRules);
if ($this->validator->passes()) {
$this->name = \Input::get('studentName');
$this->code = \Input::get('studentCode');
if ($this->save()) {
return \Response::make("You have registered the subject successfully !");
} else {
return \Response::make('An Error happened ');
}
} else {
Return $this->validator->messages()->first();
}
}
}
I am just trying to insert a new row with three Columns (I call the insertNew function on instance of Student)
1- ID automatically incremented
2- Special Code
3- Name
And I got this above Msg
What's I have tried till now :
removing all relations between from this model and other models
that has this one in the relation
Removed the validation step in insertNew()
Removed the all Input class calls and used literal data instead.
note that I use similar Inserting function on other Models and it works flawlessly
Any Comments , Replies are appreciated :D
Solution
I solved it and the problem was that I am accessing the validator
$this->validator = \Validator::make(\Input::all(), $this->newValidationRules);
And it was because I forgot that
/**
* The validator object.
*
* #var Illuminate\Validation\Validator
*/
protected $validator;
I had a similar problem. But to me, changing this code:
if ($this->validator->passes()) {
$this->name = \Input::get('studentName');
$this->code = \Input::get('studentCode');"
to this:
if ($this->validator->passes()) {
$this->setAttribute ("name" , \Input::get('studentName'));
$this->setAttribute ("code" , \Input::get('studentCode'));"
solved it.