September 14, 2014 — kyle.huynh205
Laravel cheetsheet
Full and great cheat-sheet site for Laravel: click here , in case you lost your internet connection, here is PDF copy
php artisan key:generate: generate encryption key for applicationphp artisan migrate:install: Create the migration repositoryphp artisan migrate:make name: Create a new migration filephp artisan generate:migration --fields="name:string, description:text, started_at:timestamp, ended_at:timestamp"create_event_table$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'|'restrict'|'set null'|'no action');:- ON DELETE CASCADE (when a referenced parent table row is removed all the child are removed automatically)
- The ON DELETE SET NULL action allows data that references the parent key to be deleted, but not updated. When referenced data in the parent key is deleted, all rows in the child table that depend on those parent key values have their foreign keys set to null.
- ON DELETE NO ACTION (which is the default) prevents deleting a parent when there are children (would be nice arrangement for real life)
php artisan db:seed: import seed data to databaseInput::server("REQUEST_METHOD") == "POST";check the server property REQUEST_METHOD . If this value is POST we can assume that the form has been posted to this actionphp artisan servestart development server withhttp://localhost:8000Laravel 4 provides a great validation system, and one of the ways to use it is by calling the Validator::make() method. The first argument is an array of data to validate, and the second argument is an array of rules.
Validator::make(Input::all(),[ "username" => "required", "password" => "require"]);Redirect::back()->withInput()->withErrors($validator);avoid how refreshing the page most often re-submits the form(it will it asking us for permission to re-submit data.), it will store the posted form data in the session, and redirect back to the previous page!Auth::user()->usernameget username for user table by Laravel authentication built-in libraryValidator::make(Input::all(),[Validating registration form Laravel rules
"username" => "required|alpha_dash|unique:user",
"first_name" => "required",
"last_name" => "required",
"email" => "required|email",
"password" => "required|confirmed",
"password_confirmation" => "required",
]);php artisan generate:model Eventgenerating resourceful model classphp artisan generate:seed Categorygenerating resourceful seed data based on created modelphp artisan generate:controller EventControllergenerating resourceful controller classphp artisan dump-autoloadRegenerate framework autoload filesecho app_path();Path to the ‘app’ folderecho base_path();Path to the project’s root folderecho public_path();Path to the ‘public’ folderecho storage_path();Path to the ‘app/storage’ folder