I speak English, but not that good when it comes to grammar.
Now this question is about Laravel Framework.
Lately I've been developing a project using Laravel, normal day. But then, I started to make a migration
php artisan make:migration create_quizs_table --create=quizs
Created a few create query using php artisan tinker, yes all goes fine.
But then I refresh my migration just for curiosity, php artisan migrate:refresh, and here's what I get when I try to load pages using table quizs, after I:
Created a Quiz Model, App\Quiz.php from artisan,
try Eloquent technique to retrieve simple database ::all() query.
The Error on my browser:
There is an error ... with 'quizzes' something.
At this point, I learned that the plural of quiz is quizzes, not quizs. Is Laravel that strict on that, especially Model, since I noticed, Model use Singular without those s-es such as Quiz, Note, Book etc.
I have to figure out my English just to solve this.
Sadly, I don't have any log as `too much tinkering` corrupt my project.
But that is what I recall clearly, for I learned the plural of quiz from Laravel, thanks I guess. I believe you can recreate the issue too by creating quizs table, with wrong grammar.
Related
In a previous question, I asked about how to write a trigger and gave a decent example of one way to write it in a laravel 5.X migration file. (note: hard/raw coded)
Referenced Question:
https://www.stackoverflow.com/questions/39177303/laravel5-x-database-triggers-and-possible-best-practices
However, as the title states, does anyone know how to write a database routine/subroutine in a laravel migration file??
Or
Does anyone know of a clean way to implement using laravel's methods to create a migration file that will make subroutines or routines within a database?
Sorry for this very noob question. I started PHP for almost 1 months. I don't have any background in programming. Without using a framework. A friend of mine lets me work with him on a project. which uses a php it had a framework which was built by them. Since their team lead decided to pick a new framework, which was laravel and rewrite the whole project. Luckily he still let me join them. I've been working only on the small stuff in the project. I haven't touched any database related during my work with them. after a week I had to go back to my home town so I can't work with them anymore. Since then I keep reading the laravel documentation. And tried database. I stumbled on this eloquent which builds query from class names or method name. I was so confused. But I don't know what to search for or how does this work. I scanned the code and hell it was so advance I give up. I can't sleep on how to make this. so if any of you could give me an example how this works I would be very happy.
class User extends Model
{
}
which when called like this
User::all()
it will give some data. but how.? it this part of php? All I see about php mysql is about pdo. I can't find any examples like this
A model in laravel is linked to a snake cased table. This means that a User model maps to a users table but this can be overwritten by adding this in your model class
protected $table == "my_custom_table_name"
When you use User:all() It will return all the records in the users table. It simply runs select * from users beneath it.
The all() method is defined in the extended model class. You can check it out to understand how laravel automagically does stuff.
I'm currently building a new application which runs on an existing database - which is already in production. This new app is built in Laravel 4 and has a few migrations to make schema changes that are required.
Requirements are to use Percona Toolkits pt-online-schema-change to issue schema changes, however I cannot find anywhere how to use this from within a migration - just the standard CLI interface. I need some way to tie together the schema change within the migration and pt-online-schema-change.
I don't want to loose all the benefits that come with writing migrations or using the Laravel schema builder. I was hoping there is a simple way I'm not seeing to use Percona Toolkit within them. I have thought of using exec() but I'd prefer to avoid this if possible.
When "Googling" periodically over the past few weeks, I could not find anything which resembles using Percona Toolkit within a migration. Surely this is a problem that has been solved already?
If my approach is flawed, please tell me! :)
You probably will be able to execute it like this in your migrations:
public function up()
{
exec('pt-online-schema-change --alter "ADD COLUMN c1 INT" D=sakila,t=actor', $output, $return);
if ( ! $return) {
throw \Exception('Error migrating '.__FILE__);
}
}
I am totally new to FuelPHP, ORM and migrations in general so sorry if I come across like a newbie, but I've been struggling with this for a few hours now so I thought I'd ask for help. I think I'm either doing something wrong or missing something fundamental.
I am trying to create a users model, for simplicity let's say it just has a string representing name.
I was under the impression that using the following two Oil commands would create a users model, and an associated migration which after running would build an associated table:
php oil generate model user name:string
oil refine migrate
This does successfully create the model and migration, but running the second command doesn't build the table in the database.
If I run these commands on the other hand:
php oil generate migration create_user name:text
oil refine migrate
The migration is created and the table is built in my database. I noticed that perpending 'create_' to the migration name made it possible to create the table, whereas leaving it off (i.e php oil generate migration user name:text) doesn't insert the table to the DB. I noticed the generated migrations with and without the 'create_' are significantly different.
So my question ultimately is, how do I create the model, associated migration which creates the table? Or, am I totally misunderstanding something?
Thanks!
If you get 'Already on the latest migration', your migration tracking data is out of sync. Migrations are tracked both in the database (a table called migration) and a config file in your environment folder called migrations.php.
If there is already an entry in one of them, oil will not run it again.
So you can't just delete the table through the backdoor and then run the migration again. You'll have to run a 'migrate:down' to revert the last migration, or if you delete all, also delete the migration table and config file.
Again, credit to Harro Verton on the FuelPHP forums.
Hey.
I'm having a hard time migrating changes I've done i my config/doctrine/schema.yml file.
I added the column age to the user table. Then I did a php symfony doctrine:generate-migrations-diff followed by php symfony doctrine:migrate .
Looking in my database, the column age is now added, without deleting any data.
But, my /lib/model/doctrine/base/BaseUser.class.php is not changed, there is no age field or functions for age . So I also did the command php symfony doctrine:build-model . Finally the model is updated/migrated too.
So I wonder, is this the only way? Seems like a lot of work, and I'm afraid to miss something each time doing it.
Could I go right into phpmyadmin, add changes in the database there and just do a php symfony doctrine:build-schema , and like that skip the migration part (two commands).
Also when the comes to use of models, am I right that /lib/model/doctrine/User.class.php is where I can make functions and such for my User "data class"? Like, making a function isFemale . If not, where would that kind of function be?
This might be a bad question, but why is the model layer inside the /lib/doctrine path? As far as I have learned, you keep modules inside apps, where you create your view and controller. Why should the model be outside. Like this I can make models without attached controller and view?
Thanks.
Why should the model be outside
Because models can be used everywhere in your project, in example, in different applications and modules.
Could I go right into phpmyadmin, add changes in the database there and just do a php symfony doctrine:build-schema , and like that skip the migration part (two commands).
Of course you can, but migrations are a good approach to track your schema when deploying to production or working in team.
Here how I use doctrine migrations (simple use-case):
Add a column age to my User model in schema.yml
./symfony doctrine:generate-migrations-diff. Migration class(-es) have been generated.
./symfony doctrine:migrate. Column age successfully added to table.
./symfony doctrine:build --all-classes. Build forms/filters/models
That's it. The main idea is that doctrine:generate-migrations-diff class:
Gathers information about all your models' structure (php-representation of schema.yml)
Compares your schema.yml and info from (1)
Generates migration classes based on difference
Also when the comes to use of models, am I right that /lib/model/doctrine/User.class.php is where I can make functions and such for my User "data class"? Like, making a function isFemale . If not, where would that kind of function be?
Yes, you can add such method to User model because it's about users.