I have a store built with Opencart. Now I decided to use Laravel's Eloquent ORM to speed up further modifications. But the problem is that Opencart already has database connection (using mysql PDO driver) and I don't want to create new connection with Laravel as I want to keep performance as high as possible, and multiple db connections could be expensive.
So can I use already created PDO instance in Laravel Eloquent ORM?
Related
I was trying out Laravel Scout's database driver and I am wondering how it works behind the scene. Where does it store the indices and how does it perform the searches?
I noticed, Laravel creates tables via storage engine as MyISAM which does not support relational features.
I have setup the foreign keys via migrations but when I checked in Phpmyadmin, it shows no relational features due to storage engine being MyISAM.
I have read that if I change to InnoDB the relationships can be applied.
But my question is if I cannot add relationships, then why Laravel took that storage engine as MyISAM ?
Is there no need to put relationships in database ?? That would make my database vulnerable.
What is the best practice as per Laravel ?
Actually, it was not necessarily Laravel that made the database tables MyISAM. If you do not specify it, the tables will be created using the default storage engine of your MySQL version/installation. In your case it was probably MyISAM.
To ensure InnoDB is used, edit your config/database.php file and set
'engine' => 'InnoDB',
I'd like to use a DynamoDB table for my Laravel cache. I added https://github.com/baopham/laravel-dynamodb to the project, but now I have no clue regarding how to configure Laravel to use DynamoDB, what should I do?
Thanks
The library you refer here is for integrating Eloquent with DynamoDB. They say here you can use it and write your own cache driver.
But Laravel 5.8 (as per the release notes) has it's own DynamoDB cache driver so I would use that instead. Please check the config/cache.php file where you can find a 'dynamodb' store which looks quite straightforward to configure.
I am working on a school project with multiyear database built in laravel.
My requirement is to feed data for every new academic year in some tables. I have a main (superadmin) db and separate school's db for every school. I need to connect to school db, n process is i have kept superadmin db details in .env file then it fetches particular school's db details and makes a connection to that school db through middleware.
My question is when i execute migration and seeding command it connects to superadmin db and performs respective operation. But i want to execute migration/seeding one by one for every school's db.
Add a extra entry into config/database.php For example mysql2
On each of your models specify the database it is related to. For example on your School Model
protected $connection = 'mysql2';
Now you can just run your seeder like you have 1 database , since the connection is specified on your models the correct database will be seeded.
you can run the command
php:artisan db:seed --class="className" --database=mysql2
I have created the schema through MySQL Workbench and synchronized it with the database.
All the tables are there in database. Now when I use the
php artisan migrate
command, is there an option to take the fields director from the database instead of specifying the fields name.
Also could you please suggest any other tools on github.
Laravel Migrations Generator will help us generate migration source code from existed database in Laravel 4.
so if you already have your sql schema, created in mysql workbench, then you'd need to put that schema into laravel migrations using the schema builder.
there are tools that make this part easier:
http://www.laravelsd.com/ - kinda like mysql workbench, with an export possibility to laravel migration code
https://github.com/XCMer/larry-four-generator writes existing databases to laravel migration code
Another option is to use our tool Skipper (https://www.skipper18.com) We introduced Laravel support a month ago and now, in a beta phase, it is free for Laraver users.
Skipper allows you to import your MySQL Workbench project directly (or it is possible to import existing database too) and then export migrations and object files from Skipper to your Laravel project.
The benefit of this solution is that you can maintain your ORM schema directly in Skipper and continuously update model object files and create new migrations automatically from the application without the necessity to write any code manually.
If you want to try it, you can download it here https://www.skipper18.com/en/download, and in the initial application license screen select "Laravel Beta license".