vanderb

Experience

3,400

5 Best Reply Awards

  • Member Since 2 Months Ago
  • 0 Lessons Completed
  • 0 Favorites

22nd September, 2017

vanderb left a reply on Accessing Props From A Method • 2 months ago

  • How and where you call myMethod?
  • What type is imgType in template, ?

Have you checked before, what value is imgType?

{{ imgType }}

If imgType is a simple, not dynamic string, you can pass this without colon-based-prop.

<span img-type="MYIMAGETYPE"></span>

If you pass a string, not as a variable, you have to set it with single quotation marks

<span img-type="'MYIMAGETYPE'"></span>
```

vanderb left a reply on How To Pass An Array To Ajax And Accessible In Controller? • 2 months ago

Why you should do that?

Or do you want to get the html from view2?

Then you can set in your Controller

\View::make('view2')->with(['arr' => $arr]);

Dont think you can do ajax-calls over multiple methods/controllers, unless you create a confusing, nested ajax-construction.

But maybe you can take a look into Guzzle.

http://docs.guzzlephp.org/en/stable/

https://medium.com/laravel-5-the-right-way/using-guzzlehttp-with-laravel-1dbea1f633da

vanderb left a reply on How Can I Highlight Some Words From A Paragraph • 2 months ago

I recommend to use computed-propeties, so you dont have to set the filter-logic in template.

https://vuejs.org/v2/guide/computed.html#Computed-Properties

vanderb left a reply on Html Array Inputs How To Show One By One Value. • 2 months ago

There are missing so many informations.

  • Whats the html-array, and where and how it's declared?
  • Where should they be shown?
  • ...

Tell us more about, what you want to do.

vanderb left a reply on Accessing Props From A Method • 2 months ago

You should not declare method-names with qutotation marks

methods: {
    myMethod() {
        console.log(this.img_type);
    }
}

Rename your prop in vue to imgType. Vue formats the props from kebab-case (in template) to camelCase (in vue itself).

props: ['imgType']
<span :img-type="MYIMAGETYPE"></span>

vanderb left a reply on Reuse Controllers • 2 months ago

At first: There could not be two routes with the same name (unless they are in different prefixed groups).

There could be better solutions for that, but that's my way to deal with custom functions/methods.

Maybe you can create a custom Service class for that to outsource methods, which are not used for route-bindings.

  • Create a new folder "Services" in app-folder
  • Create a new PHP-File, e.g. AgendaService.php
<?php
namespace App\Services;

class AgendaService {
    /**
     * Obtener el nombre a mostrar de una cita para mostrar en el calendario.
     *
    * @param $cita
    * @return string
    */
    public static function getNombreCita($cita)
    {
        $tituloCita = null;
        if (! empty($cita->cli_partner_id)) {
            $tituloCita = $cita->partner->nombre;
        }
        if (! empty($cita->centro_id)) {
            if ($cita->centro->id == $cita->centro->centro_id) {
                $tituloCita = $cita->centro->nombre.' / '.$cita->centro->denominacion;
            } else {
                $tituloCita = $cita->centro->centroEmpresa->nombre.' / '.$cita->centro->denominacion;
            }
        }

        return $tituloCita;
    }
}

In your Controller

use App\Services\AgendaService;

'title' => AgendaService::getNombreCita($cita),

You could outsource your filter-logic in another method or own Service

public static function filter($citas) {

    if (!empty(request()->get('filtr_consejero'))) {
        $citas->where('cli_contacto_id', request()->get('filtr_consejero'));
    }

    if (!empty(request()->get('filtr_empresa'))) {
        $centros = Centro::where('centro_id', request()->get('filtr_empresa'))->pluck('id');
        $citas->whereIn('centro_id', $centros);
    }

    if (!empty(request()->get('filtr_centro'))) {
        $citas->where('centro_id', request()->get('filtr_centro'));
    }

    return $citas;
}
//Filtros
$citas = AgendaService::filter($citas); 

vanderb left a reply on How To Pass An Array To Ajax And Accessible In Controller? • 2 months ago

var arr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24];

...

data: {code: code, array: arr}


MyController {

    public function ajaxRouteEndoint(Request $request) {
        
        $array = $request->get('array');

        // Do whatever you want to do

        $html = '<h1>Boo</h1>';
        
        // Return as json
        return response()->json(['array' => $array, 'html' => $html]);
    }

}

            success: function (response) {
        arr = response.array;

                w = window.open(window.location.href,"_blank");
                w.document.open();
                w.document.write(response.html);
                w.document.close();
            },

20th September, 2017

vanderb left a reply on Updating A View From Database • 2 months ago

Ok. You have to add your new credit-value to the response.

If you do the change via axios, you have to call a function under then, which updates your vue-value with that from response.

then(response => {
    openNotification(...);

    this.credit = response.data.credit;
}

vanderb left a reply on Updating A View From Database • 2 months ago

But what is the main problem for now, are there any console-errors or something?

In the "getMyCredit"-Method you try to fill a data-key named this.myCredits. But you dont declared this.myCredits in the data-part.

vanderb left a reply on Location Of File Using PutFile • 2 months ago

Whats the root path of your Storage-Driver? (config/filesystems.php*)

localhost/sites/... roots into /public

By default the Storage-Driver roots into storage/... based on the storage_path-helper

vanderb left a reply on Validate If At Least One Sub Array Has A Key • 2 months ago

Maybe there is a better way. If not you could do this by set the rule based on request manually

$selected = array_filter( $request->get('system_types'), function ($a) { return array_key_exists('selected', $a); });

if($selected) {
    $custom_rules['system_types.*.system_count'] = 'required';
}

vanderb left a reply on Laravel Problem With Pagination • 2 months ago

Why not use Relationships

https://laravel.com/docs/5.5/eloquent-relationships

Then you dont have to deal with constructs like

$image = Images::where('product_id','=', $product->id)->take(1)->get();

With Relationships you can get the image directly via

$images = $product->images;
// Or Single
$image = $product->images->first();

To use that, you have to update your database with indexes etc.

It could be a bit tricky but it's worth it.

vanderb left a reply on How To Check Mail Is Send Successfully In Laravel • 2 months ago

Its a complex topic.

For a simple Check you can use try/catch

try {
    Mail::send(...);

    return 'Success';
} catch (Exception $ex) {
    // Debug via $ex->getMessage();
    return 'We've got errors!';
}

To check bounced mails it could be more complex

https://stackoverflow.com/questions/5402051/how-do-i-track-the-bounced-emails

vanderb left a reply on How Can I Hide The Title Bar Of Sublime Text 3 • 2 months ago

On Mac go to View -> Hide Tabs.

Think on Windows it should be the same.

vanderb left a reply on Failed To Load Resource: In Laravel 5.5.4 • 2 months ago

Mhh, thought laravel mix will copy the bootstrap-fonts to /public folder by default.

So if not, you have to do that manualy.

Either with the copy-method

https://laravel.com/docs/5.5/mix#copying-files-and-directories

or simply by hand

Copy all font-files from /node_modules/bootstrap-sass/assets/fonts/bootstrap to /public/fonts

Maybe there is already a vendor-folder in public (not in root), and the font-path in sass-files are not correct. If not, the 2 ways above should help.

19th September, 2017

vanderb left a reply on Model Binding Is Not Working For Some Routes • 2 months ago

Ah ok, sorry missunderstood you. Maybe one line beneath the getRouteKeyName in documentation is the solution

"Explicit Binding"

https://laravel.com/docs/5.5/routing#route-model-binding

vanderb left a reply on Pass Variables To @include Array • 2 months ago

All things in the @include-direction is by default php-code.

So I think you can get rid of the @if/@endif in the include-directive

@include('partials.finance-calculator',[
        'price' => isset($vehicles->price) ? $vehicles->price : '25000',
         'deposit' => '5000', 'term' => '', 'year' => date('Y')])

vanderb left a reply on How To Customize Validation Messages? • 2 months ago

There are two ways, to do this.

  1. Use translation-files under "resources/lang/LANG_CODE/validation.php"

Look for the custom-part, there you can set custom validation-messages.

  1. You can set your messages directly in the validation-part in your Controller. That should look similar to the custom-part in the translation-files

    $this->validate($request, [ 'fiscal_code' => 'nullable|string|max:13|required_without:vat_code' ], [ 'fiscal_code' => [ 'string' => 'This field should be a string', 'nullable' => 'This field is nullable', '....' => '...' ] ]);

vanderb left a reply on Model Binding Is Not Working For Some Routes • 2 months ago

Laravel formats class-names from camel-case into snake-case. Maybe you can change your route to 'shop_specific_products' or you can set a custom slug in your Model

public function getRouteKeyName()
{
        return 'slug';
}

https://laravel.com/docs/5.5/routing#route-model-binding

vanderb left a reply on Failed To Load Resource: In Laravel 5.5.4 • 2 months ago

Did you install the npm-packages and recompile your assets?

18th September, 2017

vanderb left a reply on How Can I Display 3 Posts In Slider For Whole Day And Changes On Next Day Randomly In Laravel 5.5? • 2 months ago

I assuming your post-table have a created_at-date-field.

$randomPost = Post::where('created_at', '>=', date('Y-m-d').' 00:00:00')->all()->random(3);

vanderb left a reply on Cannot Get And Set Datepicker In Input Field With V-model • 2 months ago

Cant see any save-button? What action is called after click? (vue-method or normal form-request)?

13th September, 2017

vanderb left a reply on Laravel Not Throwing Error Saving • 2 months ago

@ArthurDiniz Information like, how you registered your routes etc. But I think you use resource-routes, so check if the missing csrf-field will do it.

vanderb left a reply on How Do I Preselect A Bootstrap Combobox Using Jquery. • 2 months ago

There is no need for jquery, until you plan to use it for select-handling anyway.

You have to set the default-variable in Controller or - bad but it works - in view like

@php
    $selected_user = 1;
@endphp

// ...

<option value="..." {{ $selected_user == $user->id ? 'selected' : '' }}

vanderb left a reply on Laravel Not Throwing Error Saving • 2 months ago

There are lots of missing information:

Maybe you missed the csrf-token-field?

{{ csrf_field() }}

vanderb left a reply on Foreach Target First • 2 months ago

@if($k == 0) @endif 

Should work, please check, if the keys are increasing numbers like 0,1,2,3 or not.

Maybe alternatively you could wok with

@if($news->first() == $item) @endif

vanderb left a reply on Delivery Private Files Based On Profiles • 2 months ago

Hi,

first you have to create the private-folder and only give apache read-access.

Create a custom route for that, with filename as route-parameter

Route::get('private/{uid}/{filename}', '[email protected]');

Then in your Controller-Method

public function getFile($uid, $filename) {
    if($uid != auth()->user()->id) {
        return abort(403);
    }

    $filepath = storage_path('private/' . $filename);
    return response()->file($filepath);
} 

Maybe you can check from db, if the file belongs to user, so you can get rid of the uid-section, and handle a auth-check with Eloquent-where e.g. But I dont know your DB-Structure, so that should work.

vanderb left a reply on Better Way To Associate A User With A Created Object • 2 months ago

Is the post created/updated by current authenticated user? Then you can use auth()->user()

$post->user_id = auth()->user()->id;

vanderb left a reply on Group By 3rd Level Relationship • 2 months ago

Dont know exactly your database-structure, but I think you need another relation set in your Category-Model:

public function questions() {
    return $this->hasMany(Question::class);
}

Then you can write

$categories = Category::with('questions.products')->get();

vanderb left a reply on Modified Config Settings Seem To Disappear After Changing Route. • 2 months ago

Sorry, that was my fault. Didn't saw the config-set.

Maybe you can try to use a custom Middleware.

https://laravel.com/docs/5.5/middleware

vanderb left a reply on Cannot Get And Set Datepicker In Input Field With V-model • 2 months ago

Hi,

  • Which datepicker-plugin, there are more than one I think
  • Please show your code, we can't see, where are potential errors in code.

vanderb left a reply on Modified Config Settings Seem To Disappear After Changing Route. • 2 months ago

Hi,

'database' => '',

Why this is empty? Maybe that is why the exception says "No database selected"?

vanderb left a reply on View PDF Inside HTML Page • 2 months ago

Hi, Maybe you search for pdf.js... https://mozilla.github.io/pdf.js/

12th September, 2017

vanderb left a reply on How To Customize The Laravel Default Command In The Package? • 2 months ago

Maybe you dont set a command-signature? The documentation could be helpful

https://laravel.com/docs/5.5/artisan#writing-commands

vanderb left a reply on Cannot Use Action • 2 months ago

In addition: Why not use named routes? So you can simply use route()-helper for that. That makes it also easier to work with Route-Params etc.

https://laravel.com/docs/5.5/routing#named-routes

vanderb left a reply on Why Eloquent Returns Array In A Specific Environment • 2 months ago

@dfc643 A link to your topic to laravel-china.com or a quick guide of the solution maybe help other users in future. Thanks.

vanderb left a reply on Optional Sass Import • 2 months ago

Ah ok. Just add the !default-flag to your variables in your variables.scss

$example-color: #fff !default;

So you can override the variables either before or after variables-import, because Sass looks for the default flag.

If there is no override the default-value used.

Thats the way, framework like bootstrap or foundation do.

Maybe here you can read more about that https://robots.thoughtbot.com/sass-default

vanderb left a reply on Old In Select • 2 months ago

But what is in old('role') after you submit the form? Because on normal request old is logically empty.

11th September, 2017

vanderb left a reply on Change Order Items • 2 months ago

Ah, ok. Computed variables are not changing, if original variable changes. So maybe you have to use a custom method, instead of computed variable. Just copy the method from computed to methods:

methods: {
    reverse: function() {
        return _.reverse(this.names);
    }
}

Maybe you have to call reverse as function, just try&error

<div v-for="user in reverse()">
    <user :us="user"></user>
</div>

vanderb left a reply on Old In Select • 2 months ago

And, what is in old('role') after request/redirect?

vanderb left a reply on Change Order Items • 2 months ago

Think it should be the same way as @abusalameh said

data() {
    return {
        //...
    }
},
computed: {
    reverse: function() {
        return _.reverse(this.names);
    }
}

<div v-for="user in reverse">
        <user :us="user"></user>
    </div>

vanderb left a reply on Old In Select • 2 months ago

simple use dd for dumping

dd($roles)

vs.

dd(old('role'))

vanderb left a reply on Having Issues With Saving • 2 months ago

Like @danmatthews said, there are no needs to use custom accessor, to update the PersonID.

Second thing is, you can laravels class-injection.

public function process(Request $request, Person $person) {
    $personID = $request->get('personID');
    $newPerson = $person->create([
    'personID' => $personID
    ]);
}

Dont know exactly, checkComment should do, maybe you can tell more about that.

vanderb left a reply on Old In Select • 2 months ago

Check if there are differences between $role and old('role'). $role should be a simple key/value-based array, old('role') one of the keys of the $role-array.

vanderb left a reply on Change Order Items • 2 months ago

As default laravels js/vue-stack served with lodash. In addition to ausalameh you can simply use lodashs reverse-methods:

_.reverse(this.names);

vanderb left a reply on Emitted Event Not Working In Firefox. • 2 months ago

Ah ok, think firefox ignores the self or cant resolve that in the Event-Callback. Are there any console-messages in Firefox?

vanderb left a reply on Optional Sass Import • 2 months ago

Just wrap your styles in the optional file as a sass mixin: @mixin optional_file { .test { color: red } // other styles here }

Then use the if-statement of sass to include the mixin

@import "optiona_file";
@if $someval == true {
    @include optional_file;
}

vanderb left a reply on Redirecting All Subdomains To Https://example.com • 2 months ago

Dont know if its legit, but why you dont use a Middleware for that?

vanderb left a reply on Emitted Event Not Working In Firefox. • 2 months ago

Dont think that fix it, but one question: Why you set a named function?

filterPeople: function filterPeople() {

Think you should set filterPeople-Method as a anonymous function, right?

filterPeople: function() {

or with ES6

filterPeople() {
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.