marcov4lente
8/23/2016 - 9:37 AM

Laravel Operations

Laravel Operations

Installing Laravel

composer create-project --prefer-dist laravel/laravel blog

Enabling Form and HTML support

Add the following lines in the require section of composer.json

"laravelcollective/html": "5.*"

Run composer update

$ composer update

Add provider to providers array in config/app.php

'Collective\Html\HtmlServiceProvider::class' 

Add form alias to aliases array in config/app.php

'Form' => Collective\Html\FormFacade::class,'Html' => Collective\Html\HtmlFacade::class

File management

Uploading FIle

$file = Request::file('filefield');
$extension = $file->getClientOriginalExtension();

$newFileName = 'xyz';

$path = $file->storeAs('/',$newFileName.'.'.$extension, 'private');
        return $path;

Checking a file's existance

Storage::disk('private')->exists($fileName)

Deleting a file

Storage::disk('private')->delete($fileName)

Eloquent

Access the last query

\DB::enableQueryLog();

# query....

$queries = \DB::getQueryLog();
$last_query = end($queries);
var_dump($last_query);
exit;

Where group

->orWhere(function($query) use ($anotherStarttime,$anotherEndtime){
  $query->where('starttime', '>=', $anotherStarttime);
  $query->where('endtime', '<=', $anotherEndtime);
})

Raw queries

$someVariable = Input::get("some_variable");

$results = DB::select( DB::raw("SELECT * FROM some_table WHERE some_col = :somevariable"), array(
   'somevariable' => $someVariable,
 ));