Custom validator in Laravel 5

Try the following: Make a bind class where you can implement each rule you want extending Validator class. Make a service provider that extends ServiceProvider. Add your custom validator provider at config/app.php file. You can create the bind at Services folder like this: namespace MyApp\Services; class Validator extends \Illuminate\Validation\Validator{ public function validateFoo($attribute, $value, $parameters){ return … Read more

Eloquent Parent-Child relationship on same model

You should use with(‘children’) in the children relation and with(‘parent’) in the parent relations. For your code to be recursive: public function parent() { return $this->belongsTo(‘App\CourseModule’,’parent_id’)->where(‘parent_id’,0)->with(‘parent’); } public function children() { return $this->hasMany(‘App\CourseModule’,’parent_id’)->with(‘children’); } Note: Make sure your code has some or the other exit conditions otherwise it will end up in a never ending … 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

required_if Laravel 5 validation

assuming that list_type is the name of the select box to choose from (values : selling or rent) use it this way “sale_price” => “required_if:list_type,==,selling” what does this mean? : the sale price is only required if the value of list_type is equal to selling do the same for rent_price edit public function rules() { … Read more