Laravel Events Cheatsheet


Event::fire('', array($bar)); Event::listen('', function($bar){}); Event::listen('foo.*', function($bar){}); Event::listen('', 'FooHandler', 10); Event::listen('', 'BarHandler', 5)

Laravel Pagination Cheatsheet


Auto-Magic Pagination Model::paginate(15); Model::where('cars', 2)->paginate(15); "Next" and "Previous" only Model::where('cars', 2)->simplePaginate(15); Manual Paginator Paginator::make($items,

Laravel Eloquent Cheatsheet


Model::create(array('key' => 'value')); Find first matching record by attributes or create Model::firstOrCreate(array('key' => 'value')); Find first record by attributes or instantiate Model::firstOrNew(array(

Laravel Database Cheatsheet

 Laravel, MySQL

Laravel Database Eloquent DB::connection('connection_name'); DB::statement('drop table users'); DB::listen(function($sql, $bindings, $time){ code_here; }); DB::transaction(function(){ transaction_code_here; }); Cache a query for

Laravel URLs Cheatsheet

 Laravel, PHP

URL::full(); URL::current(); URL::previous(); URL::to('foo/bar', $parameters, $secure); URL::action('FooController@method', $parameters, $absolute); URL::route('foo', $parameters, $absolute); URL::secure('foo/bar', $parameters); URL::asset(

Laravel Log Cheatsheet


Log::info('info'); Log::info('info',array('context'=>'additional info')); Log::error('error'); Log::warning('warning'); Get monolog instance Log::getMonolog(); Add listener Log::listen(function($level, $message, $context)

Laravel App Cheatsheet


App::environment(); Test equal to App::environment('local'); App::runningInConsole(); App::runningUnitTests();

Laravel Routing Cheatsheet


Route::get('foo', function(){}); Route::get('foo', 'ControllerName@function'); Route::controller('foo', 'FooController'); RESTful Controllers Route::resource('posts','PostsController'); //Specify a subset of actions to handle on the route Route:

Laravel Configuration Cheatsheet


You may access configuration values using the Global config helper function from anywhere in the application. $value = config('app.timezone'); To set the config values at runtime, pass an array

Composer Cheat Sheet


You can use Composer to create new projects from an existing package. composer create-project laravel/laravel folder_name The install command reads the composer.json file from the current directory,

Artisan Cheat Sheet


Displays help php artisan --help OR -h Do not output any message php artisan --quiet OR -q Display this application version php artisan --version OR -V Do not ask any