Laravel 5.6 brings significant improvements to logging, error reporting, and API development. The new logging configuration provides enterprise-grade flexibility. At ZIRA Software, these improvements have enhanced our debugging and monitoring workflows.
New Logging System
// config/logging.php
return [
'default' => env('LOG_CHANNEL', 'stack'),
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'slack'],
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 14,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => 'critical',
],
'papertrail' => [
'driver' => 'monolog',
'level' => 'debug',
'handler' => SyslogUdpHandler::class,
'handler_with' => [
'host' => env('PAPERTRAIL_URL'),
'port' => env('PAPERTRAIL_PORT'),
],
],
],
];
Using Log Channels
use Illuminate\Support\Facades\Log;
// Log to default channel
Log::info('User logged in', ['user_id' => $user->id]);
// Log to specific channel
Log::channel('slack')->critical('Payment failed', [
'order_id' => $order->id,
'error' => $exception->getMessage(),
]);
// Log to multiple channels
Log::stack(['daily', 'slack'])->error('Database connection failed');
// Dynamic channel creation
Log::build([
'driver' => 'single',
'path' => storage_path('logs/custom.log'),
])->info('Custom log entry');
Collision Package
# Included by default in 5.6
composer require nunomaduro/collision --dev
Collision provides beautiful error output:
├── Syntax-highlighted stack traces
├── Editor links (click to open file)
├── Clean, readable format
└── Works with PHPUnit
API Resource Improvements
// Conditional attributes
class UserResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
// Include only when condition is true
'secret' => $this->when($request->user()->isAdmin(), $this->secret),
// Include relationship only when loaded
'posts' => PostResource::collection($this->whenLoaded('posts')),
// Merge attributes conditionally
$this->mergeWhen($request->user()->isAdmin(), [
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]),
];
}
}
// Resource collections with additional data
class UserCollection extends ResourceCollection
{
public function toArray($request)
{
return [
'data' => $this->collection,
'links' => [
'self' => route('users.index'),
],
];
}
public function with($request)
{
return [
'meta' => [
'version' => '1.0',
'api_status' => 'stable',
],
];
}
}
Eloquent Date Casting
// Automatic date casting
class Post extends Model
{
protected $casts = [
'published_at' => 'datetime',
'scheduled_for' => 'datetime:Y-m-d',
'metadata' => 'array',
'is_active' => 'boolean',
];
protected $dates = [
'created_at',
'updated_at',
'deleted_at',
'published_at', // Also works
];
}
// Custom date format
protected $dateFormat = 'U'; // Unix timestamp
Blade Component Aliases
// AppServiceProvider
public function boot()
{
Blade::component('components.alert', 'alert');
Blade::component('components.card', 'card');
}
{{-- Usage --}}
@alert(['type' => 'danger'])
Something went wrong!
@endalert
{{-- Instead of --}}
@component('components.alert', ['type' => 'danger'])
Something went wrong!
@endcomponent
Argon2i Password Hashing
// config/hashing.php
return [
'driver' => 'argon2i', // or 'bcrypt'
'argon' => [
'memory' => 1024,
'threads' => 2,
'time' => 2,
],
];
// Usage remains the same
$user->password = Hash::make('password');
if (Hash::check('password', $user->password)) {
// Valid
}
Bootstrap 4 Support
# Generate auth scaffolding with Bootstrap 4
php artisan make:auth
# Pagination views now use Bootstrap 4
{{ $posts->links() }}
Conclusion
Laravel 5.6 enhances logging flexibility, error reporting with Collision, and API resources. These improvements support both development efficiency and production monitoring.
Upgrading to Laravel 5.6? Contact ZIRA Software for migration assistance.