Laravel Community Tools by Tighten

Popular tricks

458 tricks
Pull a ready-to-go array from an Eloquent model to build a dynamic dropdown in your views
dexbarrett 12 years ago 148446
Put this in your routes.php file and you will see the SQL that Eloquent is executing when you go to pages that have any sort of access to Eloquent models. This helps a lot when debugging SQL in Laravel.
msurguy 12 years ago 125606
I spent a good hour trying to figure out why my Eloquent relationship wasn't working when I found out it was because of the difference between `$model->relationship->value` and `$model->relationship()->value`.
chadwithuh... 12 years ago 109697
Iteratively display "page breadcrumbs" - ideal for a partial.
Dombo 10 years ago 97123
Laravel 4 have a lot of features some hidden :) for some developers, i found the option to run artisan commands from route or controller, like Artisan::call('migrate:install'); or Artisan::call('migrate', [ '--path'=>'app/database/migrations' ]); Artisan::call('db:seed'); it is usefull when you don't have access to the console in share hosting environments.
Bradley 12 years ago 87410
4.0
Session time out for logged in user (middleware way) for prevent dashboard or ... access after specify time. if we use this middleware in route groups, it will be run on every request under route group. with this code we do not need to change php.ini file or laravel session config file and default settings are appropriate. Do not forget to register middleware in app\Http\Kernel : 'timeout' => 'App\Http\Middleware\SessionTimeout', Other notices: 1- we can use middleware paramaters in laravel 5.1 for custom conditions. 2- we must redirect user back (after session timeout and log out ), to prevent user navigate to come back. 3- we must show a message to user (after session timeout and log out), that you logged out after [20] minutes that you were not active. Our Persian web app for time management is: https://timenix.com If you have a better idea please comment it. ♥
ivahidmont... 10 years ago 87441
I like namespacing my controllers. I think it cleans up my structure a bit, and prevents me from having to 'composer dump-autoload' everytime I make a new controller. Though it is very convenient to namespace your controllers, your routes file can quickly become very messy. Luckily, Laravel 4.1 offers a great solution for this, namely the 'namespace' option in Route::group().
stidges 12 years ago 73639
4.1
In the official docs : http://laravel.com/docs/responses#special-responses, need to do `Response::json(...)` to create json response. Actually, if the returned value is an array or instance of arrayableinterface or jsonableinterface such as eloquent model, you could just return it, it'll be a json, magically.
egig 12 years ago 71920
Let's talk about date validation and how theses 4 rules works, as their behaviour is even more awesome than documented. What is know : - date, before and after uses strtotime PHP native function. - date_format uses date_parse_from_format PHP native function But how do we validate a date after today in a custom format ? And what to do to compare two form fields ? What is not documented is that before and after rules check if a date_format rule exists, and will use this format if needed. Example: I have french formated dates (31/01/2015), and two fields, start_date and end_date. start_date must be after tomorrow, and end_date after start_date
Lelectrolu... 11 years ago 58078
5.0