Laravel Community Tools by Tighten

Tag "database" tricks

87 tricks
Laravel has many choices for performing a query, sometimes it could be confusing, I hope this list help you to clear any doubts. If you know other way please show it in comments for add it.
luismec90 11 years ago 13937
sometime we need to autocomplete one input area and based on the value of this input area we sometime populated a dynamic dropdown . I thought it worth sharing .
hassanjama... 11 years ago 35600
How to update many-to-many relationship
nihaoit 11 years ago 15070
Here is how to beat Laravel to the punch when the database isn't playing nice. The error codes are specific to MySQL. You can easily substitute the error codes for whatever DB you are using. Below are 2 common errors. Here's a scrrenshot of the error page plus.google.com/113701899574492909448/posts/c4oAn7FDmLj
DragonI 11 years ago 12001
Using this package - http://csv.thephpleague.com/ In your controller or wherever you are calling this method from simply create a method like so: At the top you need to use: use League\Csv; That's about it, you should be good to go! Would like to thank @msurguy for his help on this too. - See more at: http://laravelsnippets.com/members/snippets/csv-data-manipulation-with-laravel#sthash.oqBx1dzA.dpuf
lstables 11 years ago 21502
With database seeding you can fill your database with dummy data with simple command. I created code that will fill users table with some data. users table consists of three columns (username,email,biog).
Clivern 12 years ago 58051
For one of my projects I needed to get an ID of the previous and next record in the DB. This could go well with portfolios, orders, blog posts, all kinds of things where you need to display next/previous entry links. Let’s say we are logged in as an admin and we are on this user’s page and we want to see next/previous user’s id. The following Eloquent code makes it easy to do that. Enjoy!
msurguy 12 years ago 17078
If you have datetime fields lets say, last_updated or registered_at, this is a nice trick to make laravel know about that fields & let it know. Just overwrite Eloquent's constants.
kbirmhrjn 12 years ago 8460
To setup configuration according to each environment you can set environmental variables. In this below example I am setting up an environmental variable "LARAVEL_ENV" with below values. staging as LARVEL_ENV staging production as LARVEL_ENV production Then in start.php under detect environment add the below code for getting the environment. You can add config files under respective folders.
ashwin-sur... 12 years ago 9878