Unit Test Laravel’s FormRequest

I found a good solution on Laracast and added some customization to the mix. The Code /** * Test first_name validation rules * * @return void */ public function test_valid_first_name() { $this->assertTrue($this->validateField(‘first_name’, ‘jon’)); $this->assertTrue($this->validateField(‘first_name’, ‘jo’)); $this->assertFalse($this->validateField(‘first_name’, ‘j’)); $this->assertFalse($this->validateField(‘first_name’, ”)); $this->assertFalse($this->validateField(‘first_name’, ‘1’)); $this->assertFalse($this->validateField(‘first_name’, ‘jon1’)); } /** * Check a field and value against validation rule * … Read more

Laravel 5 Session Lifetime

Check your php.ini for: session.gc_maxlifetime – Default 1440 secs – 24 mins. session.gc_maxlifetime specifies the number of seconds after which data will be seen as ‘garbage’ and potentially cleaned up. Garbage collection may occur during session start (depending on session.gc_probability and session.gc_divisor). session.cookie_lifetime – Default 0. session.cookie_lifetime specifies the lifetime of the cookie in seconds … Read more

Including a css file in a blade template?

@include directive allows you to include a Blade view from within another view, like this : @include(‘another.view’) Include CSS or JS from master layout asset() The asset function generates a URL for an asset using the current scheme of the request (HTTP or HTTPS): <link href=”{{ asset(‘css/styles.css’) }}” rel=”stylesheet”> <script type=”text/javascript” src=”{{ asset(‘js/scripts.js’) }}”></script> mix() … Read more

Laravel-5 how to populate select box from database with id value and name value

Laravel provides a Query Builder with lists() function In your case, you can replace your code $items = Items::all([‘id’, ‘name’]); with $items = Items::lists(‘name’, ‘id’); Also, you can chain it with other Query Builder as well. $items = Items::where(‘active’, true)->orderBy(‘name’)->lists(‘name’, ‘id’); source: http://laravel.com/docs/5.0/queries#selects Update for Laravel 5.2 Thank you very much @jarry. As you mentioned, … Read more