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 $time minutesDB::table('users')->remember($time)->get();
// Escape raw inputDB::raw('sql expression here');
Selects
DB::table('name')->get();
DB::table('name')->distinct()->get();
DB::table('name')->select('column as column_alias')->get();
DB::table('name')->where('name', '=', 'John')->get();
DB::table('name')->whereBetween('column', [1, 100])->get();
DB::table('name')->whereIn('column', [1, 2, 3])->get();
DB::table('name')->whereNotIn('column', [1, 2, 3])->get();
DB::table('name')->whereNull('column')->get();
DB::table('name')->whereNotNull('column')->get();
DB::table('name')->groupBy('column')->get();
// Default Eloquent sort is ascendantDB::table('name')->orderBy('column')->get();
DB::table('name')->orderBy('column','desc')->get();
DB::table('name')->having('count', '>', 100)->get();
DB::table('name')->skip(10)->take(5)->get();
DB::table('name')->first();
DB::table('name')->pluck('column');
DB::table('name')->lists('column');
// JoinsDB::table('name')->join('table', 'name.id', '=', 'table.id')
->select('name.id', 'table.email');
Inserts, Updates, Deletes
DB::table('name')->insert(['name' => 'John', 'email' => 'john@example.com']);
DB::table('name')->insertGetId(['name' => 'John', 'email' => 'john@example.com']);
// Batch insertDB::table('name')->insert(
['name' => 'John', 'email' => 'john@example.com']
);
// Update an entryDB::table('name')->where('name', '=', 'John')
->update(['email' => 'john@example2.com']);
// Delete everything from a tableDB::table('name')->delete();
// Delete specific recordsDB::table('name')->where('id', '>', '10')->delete();
DB::table('name')->truncate();
Aggregates
DB::table('name')->count();
DB::table('name')->max('column');
DB::table('name')->min('column');
DB::table('name')->avg('column');
DB::table('name')->sum('column');
DB::table('name')->increment('column');
DB::table('name')->increment('column', $amount);
DB::table('name')->decrement('column');
DB::table('name')->decrement('column', $amount);
DB::table('name')->remember(5)->get();
DB::table('name')->remember(5, 'cache-key-name')->get();
DB::table('name')->cacheTags('my-key')->remember(5)->get();
DB::table('name')->cacheTags(['my-first-key','my-second-key'])->remember(5)->get();
Raw Expressions
DB::select('select * from users where id = ?', ['value']);
DB::table('name')->select(DB::raw('count(*) as count, column2'))->get();
Input::get('key');
// Default if the key is missingInput::get('key', 'default');
// Check for 1 or multiple keysInput::has('key');
Input::all();
// Only retrieve 'foo' and 'bar' when getting inputInput::only('foo', 'bar');
// Disregard 'foo' when getting inputInput::except('foo');
Session Input (flash)
// Flash input to the sessionInput::flash();
Input::flashOnly('foo', 'bar');
Input::flashExcept('foo', 'baz');
Input::old('key','default_value');
Files
// Use a file that's been uploadedInput::file('filename');
// Determine if a file was uploadedInput::hasFile('filename');
// Access file propertiesInput::file('name')->getRealPath();
Input::file('name')->getClientOriginalName();
Input::file('name')->getClientOriginalExtension();
Input::file('name')->getSize();
Input::file('name')->getMimeType();
// Move an uploaded fileInput::file('name')->move($destinationPath);
// Move an uploaded fileInput::file('name')->move($destinationPath, $fileName);
No comments:
Post a Comment