[ Laravel ] 101

Install composer

$ php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
dsin@dsin-laptop:~/Desktop/composer$ php -r "if (hash('SHA384', file_get_contents('composer-setup.php')) === '7228c001f88bee97506740ef0888240bd8a760b046ee16db8f4095c0d8d525f2367663f22a46b48d072c816e7fe19959') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Installer verified
dsin@dsin-laptop:~/Desktop/composer$ php composer-setup.php
All settings correct for using Composer
Downloading 1.0.0...

Composer successfully installed to: /home/dsin/Desktop/composer/composer.phar
Use it: php composer.phar
dsin@dsin-laptop:~/Desktop/composer$ php -r "unlink('composer-setup.php');"
dsin@dsin-laptop:~/Desktop/composer$ ls
composer.phar

ref : https://getcomposer.org/download/

update composer

$ sudo /usr/local/bin/composer self-update
Updating to version ad5951218b45ee7e819246729e0b9173c2d2dd1b.
Downloading: 100%
Use composer self-update --rollback to return to version 4ecdbf89c4a3d1e5dfe73c57e3202a5e2a18c87e

need update composer, otherwise, laravel not found for any version
Install laravel

dsin@dsin-laptop:~/Desktop/composer$ composer global require "laravel/installer"
Changed current directory to /home/dsin/.composer
Using version ^1.3 for laravel/installer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
 - Installing symfony/process (v3.0.4)
 Downloading: 100% 

 - Installing symfony/polyfill-mbstring (v1.1.1)
 Downloading: 100% 

 - Installing symfony/console (v3.0.4)
 Downloading: 100% 

 - Installing guzzlehttp/promises (1.1.0)
 Downloading: 100% 

 - Installing psr/http-message (1.0)
 Downloading: 100% 

 - Installing guzzlehttp/psr7 (1.2.3)
 Downloading: 100% 

 - Installing guzzlehttp/guzzle (6.2.0)
 Downloading: 100% 

 - Installing laravel/installer (v1.3.2)
 Downloading: 100% 

symfony/console suggests installing symfony/event-dispatcher ()
symfony/console suggests installing psr/log (For using the console logger)
Writing lock file
Generating autoload files

put in the PATH environment

~/.composer/vendor/bin 

quickstart

$ composer create-project laravel/laravel quickstart --prefer-dist

test URL : http://localhost/quickstart/public

/var/log/apache2$ vim error.log
[Mon Apr 11 21:07:07.991199 2016] [:error] [pid 6848] [client 127.0.0.1:43292] PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/home/dsin/Desktop/laravel/quickstart/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied' in /home/dsin/Desktop/laravel/quickstart/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:87\nStack trace:\n#0 /home/dsin/Desktop/laravel/quickstart/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\\Handler\\StreamHandler->write(Array)\n#1 /home/dsin/Desktop/laravel/quickstart/vendor/monolog/monolog/src/Monolog/Logger.php(336): Monolog\\Handler\\AbstractProcessingHandler->handle(Array)\n#2 /home/dsin/Desktop/laravel/quickstart/vendor/monolog/monolog/src/Monolog/Logger.php(615): Monolog\\Logger->addRecord(400, Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array)\n#3 /home/dsin/Desktop/laravel/quickstart/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): Monolog\\Logger->error(Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array in /home/dsin/Desktop/laravel/quickstart/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 87, referer: http://localhost/quickstart/

Solution : chmod -R /home/dsin/Desktop/laravel/quickstart/storage folder

/quickstart/app/Http/route.php

Route::get('/', function () {
 return view('welcome');
});
That points to
/quickstart/resources/views/welcome.blade.php


Database Migrations
~/Desktop/laravel/quickstart$ php artisan make:migration create_inventories_table --create=inventories
NOTE : should be with inventory with (s)

/quickstart/database/migrations/2016_04_11_150919_create_inventories_table.php
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateInventoriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('inventories', function (Blueprint $table) {
$table->increments('vin');
$table->string('model');
$table->string('make');
$table->integer('year');
$table->double('msrp');
$table->enum('status', array('ordered', 'in stock', 'sold'));
$table->boolean('booked_listed');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('inventories');
}
}
$ sudo php artisan migrate
Migration table created successfully.
Migrated: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrated: 2016_04_11_142517_create_tasks_table
Migrated: 2016_04_11_142623_create_inventory_table
NOTE: change password in 
quickstart/.env
...
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=whateverdb
DB_USERNAME=dsin
DB_PASSWORD=pwd
...
otherwise, we got 

[PDOException] 
 SQLSTATE[28000] [1045] Access denied for user 'homestead'@'localhost' (usin 
 g password: YES)  

NOTE : keep all migration files/tables then

sudo php artisan migrate:reset

Eloquent Models = ORM

create model
 /quickstart$ php artisan make:model Inventory
Model created successfully.
/quickstart/app/Inventory.php
&lt;?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Inventory extends Model
{
 //
protected $fillable = [
'vin', 'model', 'make', 'year', 'msrp', 'status', 'booked_listed'
];

protected $primaryKey='vin';
}
more : https://laravel.com/docs/5.2/eloquent

/quickstart/resources/views/layouts/app.blade.php

<!-- resources/views/layouts/app.blade.php -->

<!DOCTYPE html>
<html lang="en">
 <head>
 <title>Laravel Quickstart - Basic</title>

 <!-- CSS And JavaScript -->
 </head>

 <body>

<div class="container">
 <nav class="navbar navbar-default">
 <!-- Navbar Contents -->
 </nav>
</div>


 @yield('content')
 </body>
</html>

Route.php

ref : validation : https://laravel.com/docs/5.1/validation
ref : https://laravel.com/docs/5.2

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s