eloquent 5.6 model create function not found - eloquent

I am using the create function in my model extends Eloquent 5.6 Model, but I don't find this function implement in Eloquent Model, please tell me where is the source create function code?

The create() method is located in Illuminate\Database\Eloquent\Builder.
Using YourModel::create() triggers Model::__callStatic() which triggers Model::__call().

Related

Do action right after entity created in SonataAdmin

is there any way that I could config my SonataAdmin to do action right after the default CRUD?
The situation is that, I've got some classes, each class has a BCode, which must be created with the entity. BCode is a tweaked crc32 string. so I need a customized action to be able to create this code with entity.id
thanks in advance
Your admin class extends the vendor/sonata-project/admin-bundle/Admin/Admin.php so you just have to implement the methods postPersist and postUpdate.
If you use doctrine as ORM you can also use the doctrine events postUpdate and postPersist as described in the documentation.

How to implement IDbContextFactory for use with Entity Framework data migrations

I am trying to use Entity Framework data migrations, as described in this post.
However, when I try to execute the Enable-Migrations step, I receive the following error in Package Manager Console:
The target context 'MyDataContext' is not constructible. Add a default constructor or provide an implementation of IDbContextFactory
So, I created a factory class that implements IDbContextFactory in the project that contains my DbContext class, but data migrations doesn't appear to recognize it.
Is there something that I should explicitly do to instruct data migrations to use this factory class?
I also hit this problem as i wrote my context to take a connection string name (and then used ninject to provide it).
The process you've gone through seems correct, here is a snippet of my class implementation if it's of any help:
public class MigrationsContextFactory : IDbContextFactory<MyContext>
{
public MyContext Create()
{
return new MyDBContext("connectionStringName");
}
}
That should be all you need.
Like #Soren pointed out, instead of using IDbContextFactory, not supported on some earlier EF Core releases (i.e. EF Core 2.1), we can implement IDesignTimeDbContextFactory<TContext>, which supports the missing ConnectionString parameter.
For a settings.json based aproach, which you can use with either of the referred interfaces, check #Arayn's sample which allows us to define "ConnectionStrings:DefaultConnection" value path
Update 1
According to #PaulWaldman's comment, on EF Core 5 support for IDbContextFactory was reintroduced. For further details, check his comment below.

Zend Framework Data Mapper problem

It has been a rough task to learn this framework. I am still stuck at quick start.
I am using PDO_MYSQL as my adapter. I have followed the tutorial to the letters.
At a point, it says to create application/models/GuestbookMapper.php and put the following code
class Application_Model_GuestbookMapper
{
public function save($model);
public function find($id, $model);
public function fetchAll();
}
Then it say to run this command
zf create model GuestbookMapper
The tutorials claims to insert additional methods. But in my case, it emptied the my GuestbookMapper class with this
class Application_Model_GuestbookMapper
{
}
Same goes with another command zf create model Guestbook. It empties the scripts, with just plain class defination.
Please help me !
Re-read the QuickStart carefully. You're probably skimming and getting hung up.
Here is the text:
A typical API for a data mapper is as follows:
class Application_Model_GuestbookMapper
{
public function save($model);
public function find($id, $model);
public function fetchAll();
}
And then...
In addition to these methods, we'll add methods for setting and retrieving the Table Data Gateway. To create the initial class, use the zf CLI tool:
% zf create model GuestbookMapper
Lastly...
Now, edit the class Application_Model_GuestbookMapper found in application/models/GuestbookMapper.php to read as follows:
Note that the first example is just that - an example. They are providing a sample interface of what your class will probably look like. The second block of text explains how to create your initial (empty) class. And the last block gives you the exact final code of the GuestbookMapper class.
Just add those methods again ;) Won't that work?

How do i use findAll method with a class in Doctrine?

I am a little bit confused with Doctrine class. I created a class and its base class in Doctrine. The class's name is User.
so..I created an object of class User.
$oUser = new User();
when I try to use the findAll method, it does not work. I found the following code on the doctrine documentation:
Doctrine_Core::getTable('User')->findAll();
I don't understand why i need to call getTable to use the findAll method when I have User class.
Am I missing something?
For Doctrine 2, you need to get the repository:
$AllUsers = EM()->getRepository('Users')->findAll();
AFAIK User object represents a single row in a table.if you need all the users you need to ask the table.

Defining a function to a Row

im making an application and i need to implement diferent level of user permits.
I coul have the function
$this->view->users->hasPermits($this->view->user);
By declaring a function on the model, an things could be easy to implement. But i would like to be able to have the next function doing the same:
$this->view->user->hasPermits();
Is there a way to do this? do i need to extend the Zend_Db_Table_Row class? any ideas?
Use Zend_Acl for this.
There is a Zend ACL tutorial on YouTube.
If $user is a Zend_Db_Table_Row from the Zend_Db_Table $users, than in User you could perform the method like so:
public function hasPermits()
{
return $this->getTable()->hasPermits($this);
}