Laravel Community Tools by Tighten

Tag "4.1" tricks

72 tricks
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 58106
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 17134
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 8481
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 9898
It truncates all tables and then it runs all seeders available.
kostaspt 12 years ago 17285
If you have an array like: array( array('key' => 'value'), array('key' => 'anotherValue'), array('key' => 'sameValue'), array('key' => 'sameValue') ); and you want to make sure that you cant have 'key' with same value twice i was searching a native way to do it, but couldn't find one - so this is my solution:
dani3l 12 years ago 10681
4.1
Perform pattern based CSRF filter on all post, put, patch, and delete requests. Just add this code snippet at the top of routes.php
Illusion 12 years ago 6599
Response::xml macro
localdisk 12 years ago 32589
This stumped me for some time and after digging around I found it works great, the uploaded file can be removed from the server as well as the database entry. works well for file sharing and image sharing sites.
blackrain 12 years ago 22527