Skip to content

Instantly share code, notes, and snippets.

@dhavalv
Last active May 10, 2016 13:22
Show Gist options
  • Save dhavalv/659b70144a5911597b959bc1c773e7b0 to your computer and use it in GitHub Desktop.
Save dhavalv/659b70144a5911597b959bc1c773e7b0 to your computer and use it in GitHub Desktop.
Laravel packages everyone should know

Laravel packages everyone should know

$user->created_at->format(‘H:i’); 
$tomorrow = Carbon::now('Europe/Vilnius')->addDay();
$howOldAmI = Carbon::createFromDate(1975, 5, 21)->age; 
if (Carbon::now()->isWeekend()) { echo 'Party!'; }
Carbon::now()->subMinutes(2)->diffForHumans();
// '2 minutes ago'
{!! Form::open(array('route' => 'admins.store' )) !!} 
{!! Form::label('name', 'Name:') !!} 
{!! Form::text('name', old('name'), ['placeholder'=> 'Name', 'required']) !!} 
{!! Form::submit('Create', ['class' => 'btn btn-primary']) !!} 
{!! Form::close() !!}
  • Laravel-4-Generators (+ Laravel-5-Generators-Extended) Speed up your Laravel workflow with generators. Laravel 5 Generator || Laravel 5 Generator Author: Jeffrey Way from Laracasts More useful in Laravel 4 version Generators examples
Laravel 4: 
php artisan generate:migration add_user_id_to_posts_table 
php artisan generate:model Post 
php artisan generate:view admin.reports.index 
Laravel 5: 
php artisan make:migration:schema create_users_table --schema="username:string, email:string:unique" 
php artisan make:migration:pivot tags posts 
php artisan make:seed posts
  • doctrine/dbal Database Abstraction Layer https://github.com/doctrine/dbal From the docs: Before modifying a column, be sure to add the doctrine/dbal dependency to your composer.json file. The Doctrine DBAL library is used to determine the current state of the column and create the SQL queries needed to make the specified adjustments to the column. Not specifically for Laravel Used for specific database operations Doctrine/dbal examples
Schema::table('users', function ($table) { 
    $table->string('name', 50)->change();
}); 
Schema::table('users', function ($table) { 
    $table->renameColumn('name', 'username'); 
});
$img = Image::make('foo.jpg')->resize(300, 200); 
$img->insert('public/watermark.png'); 
return $img->response('jpg'); 
$image = Input::file('image'); 
$filename = time() . '.' . $image->getClientOriginalExtension(); 
$path = public_path(‘images/' . $filename); 
Image::make($image->getRealPath()) ->resize(200, 200)->save($path);

jenssegers/agent examples

use JenssegersAgentAgent; 
$agent = new Agent(); 
if ($agent->is('Windows')) 
// ... if ($agent->is('Firefox'))
// ... if ($agent->isMobile()) 
// ... if ($agent->isTablet()) 
// ... $agent->setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2'); 
$agent->setHttpHeaders($headers);
$pdf = App::make('dompdf.wrapper'); 
$pdf->loadHTML('<h1>Test</h1>'); 
return $pdf->stream(); 
$pdf = PDF::loadView('pdf.invoice', $data); 
return $pdf->download('invoice.pdf'); 
PDF::loadHTML($html)
    ->setPaper('a4')
    ->setOrientation('landscape')
    ->setWarnings(false)
    ->save('myfile.pdf');
php artisan sluggable:table posts slug_column 
$post = Post::create(['title' => 'My Awesome Blog Post']); 
echo $post->slug; echo $post->getSlug(); 

Config: 'build_from' => null, 'save_to' => 'slug', 'max_length' => null, 'method' => null, 'separator' => '-', 'unique' => true, ...

  • barryvdh/laravel-ide-helper

Laravel 5 IDE Helper Generator https://github.com/barryvdh/laravel-ide-helper Also available as generated Gist Needs doctrine/dbal for DB columns Great explanation in Laracasts: https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15 laravel-ide-helper examples

  • barryvdh/laravel-debugbar

Laravel Debugbar https://github.com/barryvdh/laravel-debugbar Same author as IDE Helper: Barry van den Heuvel Integrates PHP Debug Bar Don’t forget to turn off on production! laravel-debugbar examples

Ref Link: http://www.slideshare.net/povilask007/10-laravel-packages-everyone-should-know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment