app/Providers/AppServiceProvider.php
/**
     * Bootstrap any application services.
     *
     * @return void
     */
Bootstrap any application services.
@return void
Bootstrap any application services . @return void
public function boot()
    {
        User::observe(UserObserver::class);
        Service::observe(ServiceObserver::class);
        Provider::observe(ProviderObserver::class);
        \View::composer(['layouts.app', 'dashboard.index'], function ($view){
            $servicesToPay = Auth::user()->services()->has('renewalsUnresolved')->with('renewalsUnresolved')->get();
            $feesToPay = $servicesToPay->pluck('renewalsUnresolved')->collapse();
            return $view->with('servicesToPay', $servicesToPay)
                ->with('feesToPayCount', $feesToPay->count())
                ->with('feesToPayAmount', $feesToPay->sum('amount'))
                ->with('servicesToPayCount', $servicesToPay->count());
        });
        Validator::extend('unique_date_custom', function ($attribute, $value, $parameters)
        {
            list($table, $field, $field2Value, $field2, $field3, $field3Value) = $parameters;
            $value = Carbon::createFromFormat('d-m-Y', $value)->format('Y-m-d');
            $query = DB::table($table)->whereDate($field, $value);
            if($field2Value && $field2) $query->where($field2, '<>', $field2Value);
            $query->where($field3, $field3Value);
            return $query->count() == 0;
        });
    }
public function boot ( ) { User :: observe ( UserObserver :: class ) ; Service :: observe ( ServiceObserver :: class ) ; Provider :: observe ( ProviderObserver :: class ) ; \ View :: composer ( [ 'layouts.app' , 'dashboard.index' ] , function ( $ view ) { $ servicesToPay = Auth :: user ( ) -> services ( ) -> has ( 'renewalsUnresolved' ) -> with ( 'renewalsUnresolved' ) -> get ( ) ; $ feesToPay = $ servicesToPay -> pluck ( 'renewalsUnresolved' ) -> collapse ( ) ; return $ view -> with ( 'servicesToPay' , $ servicesToPay ) -> with ( 'feesToPayCount' , $ feesToPay -> count ( ) ) -> with ( 'feesToPayAmount' , $ feesToPay -> sum ( 'amount' ) ) -> with ( 'servicesToPayCount' , $ servicesToPay -> count ( ) ) ; } ) ; Validator :: extend ( 'unique_date_custom' , function ( $ attribute , $ value , $ parameters ) { list ( $ table , $ field , $ field2Value , $ field2 , $ field3 , $ field3Value ) = $ parameters ; $ value = Carbon :: createFromFormat ( 'd-m-Y' , $ value ) -> format ( 'Y-m-d' ) ; $ query = DB :: table ( $ table ) -> whereDate ( $ field , $ value ) ; if ( $ field2Value && $ field2 ) $ query -> where ( $ field2 , '<>' , $ field2Value ) ; $ query -> where ( $ field3 , $ field3Value ) ; return $ query -> count ( ) == 0 ; } ) ; }
Bootstrap any application services.
Bootstrap any application services .
// Get the parameters passed to the rule // Check the table and return true only if there are no entries matching // both the first field name and the user input value as well as // the second field name and the second field value