Skip to content

Instantly share code, notes, and snippets.

@rrubiorr81
Created October 31, 2013 21:04
Show Gist options
  • Save rrubiorr81/7257158 to your computer and use it in GitHub Desktop.
Save rrubiorr81/7257158 to your computer and use it in GitHub Desktop.
laravel learning course
/*learning laravel*/
// dd($user->toArray()); --this two are valid... the 2nd pops out all of the users...
// dd($user::all()->toArray()); --select * anyway
dd($users->toArray()) //the output as an array
//installing and using composer
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
//installing laravel...
composer create-project laravel/laravel tlaravel --prefer-dist //used here the name tlaravel as project name
//virtual hosts configs
sudo nano /etc/apache2/sites-available/the-current-site //<VirtualHost *:80> ServerName tlaravel.dev ServerAlias tlaravel.dev DocumentRoot /media/sf_sandbox/tlaravel/public/ </VirtualHost>
//u have to put the
sudo nano /etc/hosts
//in the laravel installation there is a file "artisan" that stands for the command line related to laravel...
//see how to upgrade php to a version up 5.4, apparently laravel-artisan requieres it...
--mounted image from a box designed speficly for laravel... //https://github.com/bryannielsen/Laravel4-Vagrant
//inside artisan u can run the server with the command
php artisan serve //u can specify the port adding --port=8887
//a very imoirtant part in laravel are the routes...
Route::get('tasks', 'TasksController@index');
//the Controller
class TasksController extends BaseController
{
function index()
{
//in artisan u can do
php artisan help migrate:make //to get help from the console..
//this is called migration with the form: migrate:make [--bench[="..."]] [--create] [--package[="..."]] [--path[="..."]] [--table[="..."]] name
php artisan migrate:make create_tasks_table --create --table="tasks"
//this will create a migration file in app/migrations/
//in this file we specify the structure of the table... $table->string('title'); $table->text('body'); etc.. and run the command: php artisan migrate...
//if u made a mistake, just run: php artisan migration:rollback //and it will rollback the last migration made
//passing arguments to the view...
return View::make('tasks.index')->with('tasks', $tasks) //or
return View::make('tasks.index', ['tasks'=>$tasks]) //or
return View::make('tasks.index', compact('tasks'))
//the seeding part begins in the app/database/seeds folder. There, in the master DatabaseSeeder, in the run method u put the table to seed
//create a new page to seed and this is the one that is going to be referenced.
php artisan db:seed
//in the routes u can put
return User::find(2);
//the model will be automaticly loaded...
return User::where('username', '=', $auser)->first(); //using wheres
return User::whereUsername($auser)->first(); //laravel inferes the field from the method and by default the comparison is '='
Task::find(1);
laravel uses the convention that when naming the model in models folder, u dont have to put the table's name, only put th esingular noun and laravel assumes the plural (model::user table::users)
//check the plugin made by JWay for lavarel and sublime...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment