vanderb

vanderb

Member Since 1 Year Ago

Mannheim

Experience Points 3,400
Experience Level 1

1,600 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 0
Lessons
Completed
Best Reply Awards 5
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

22 Sep
1 year ago

vanderb left a reply on Accessing Props From A Method

  • 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?

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

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.

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

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

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?

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();
            },
20 Sep
1 year ago

vanderb left a reply on Updating A View From Database

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

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

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

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

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

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

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

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.

19 Sep
1 year ago

vanderb left a reply on Model Binding Is Not Working For Some Routes

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

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?

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

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

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

18 Sep
1 year ago

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?

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

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

13 Sep
1 year ago

vanderb left a reply on Laravel Not Throwing Error Saving

@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.

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

There are lots of missing information:

Maybe you missed the csrf-token-field?

{{ csrf_field() }}

vanderb left a reply on Foreach Target First

@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

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

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

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.

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

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.

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

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

12 Sep
1 year ago

vanderb left a reply on How To Customize The Laravel Default Command In The Package?

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

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

@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

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

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

11 Sep
1 year ago

vanderb left a reply on Change Order Items

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

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

vanderb left a reply on Change Order Items

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

simple use dd for dumping

dd($roles)

vs.

dd(old('role'))

vanderb left a reply on Having Issues With Saving

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

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

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.

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

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

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.

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() {