Reusable laravel macros.
Helpful for inspecting the response and output of your controllers during phpunit testing.
$response = $this->post(...);
$response
->dd() // prints the json response or the error response if any.
->assertOk()
->assertJson(...);
Similar to $response->dd()
but it dump the original content instead.
$response = $this->post(...);
$response
->ddO() // prints the original content of the response.
->assertOk()
->assertJson(...);
Return the mysql raw query. Include the parsed sql bindings. Also available to eloquent model.
DB::table('users')->whereRaw('active = ?', [1])->toRawSql(); // select * from users where active = 1
User::whereRaw('active = ?', [1])->toRawSql(); // select * from users where active = 1
Dd the raw sql. Helpful for debugging in between query method calls.
Enabled in local
and testing
environments only because you don't want to dd
your queries and let other people see it.
User::where('active', 1)
->dd() // dd here will print "select * from users where active = 1"
->whereNotNull('email')
->dd() // dd here will print "select * from users where active = 1 and email is not null"
->get();
For logging mysql queries.
User::where('active', 1)
->whereNotNull('email')
->log() // will log "select * from users where active = 1 and email is not null"
->get();
Cast input to boolean.
$request->input('keep_me_logged_in'); // "false"
$request->bool('keep_me_logged_in'); // false
Cast input to integer.
$request->input('quantity'); // "1,000"
$request->int('quantity'); // 1000
Cast input to float.
$request->input('price'); // "1,000.50"
$request->float('price'); // 1000.50
$request->merge($request->float(['price', 'cost', 'vat', 'discount']));