tykus

Full Stack PHP Developer at FordeHRCloud

Experience

538,050

841 Best Reply Awards

  • Member Since 3 Years Ago
  • 1256 Lessons Completed
  • 1 Favorite

21st April, 2018

tykus left a reply on Https For The Full Laravel App? • 5 hours ago

Enforce this at the web server rather than app-level. Implementation will depend on your webserver

tykus left a reply on Unexpected Syntax Error • 5 hours ago

That is not valid, you need to wrap anything that assigns key/value pairs in array() or []

$pageInfo = [
    'page_title'      => 'Clases a domicilio',
    'menu_active'     => 'Clases',
    'sub_menu_active' => 'Clases a domicilio',
];

You can use this data as $pageinfo['page_title']

tykus left a reply on Build In Timestamps And Custom Timestamps Behave Differently When Passed To Js (vuecomponent) • 12 hours ago

The reason it looks like that is because that is how Carbon is serialized. Laravel now extends Carbon, so you can override serialization (and add macros, if you wished).

You have a couple of options for deciding how to serialize the published_at date:

  1. In the model:
// Post.php

protected $casts = [
    'published_at' => 'date:Y-m-d H:i:s',
];
  1. Globally declare how Illuminate\Support\Carbon instances should be serialized:
// AppServiceProvider.php

public function boot()
{
    \Illuminate\Support\Carbon::serializeUsing(function ($carbon) {
        return $carbon->toDateTimeString();
    });
}

Now the date will behave like the created_at and updated_at properties.

tykus left a reply on I Am Trying To Upload Mp3 Audio File But Getting Error Response • 18 hours ago

There is no Laravel v4.7 ??

20th April, 2018

tykus left a reply on Get Latest Item When Several Have The Same Created_at • 1 day ago

$undoAction->id = Action::latest('id')

tykus left a reply on Cannot Redeclare App\classes\functions() (previously Declared In... • 1 day ago

Why would one Controller ever instantiate another?

tykus left a reply on Laravel Make Auth In Api • 1 day ago

Of course. The client must identify itself somehow - without a session cookie, a token is used instead.

tykus left a reply on Updated Value Not Showed In View (Show) • 1 day ago

The status relation is cached and not re-evaluated after save(); if you get a fresh() copy of the model, then the status relation will also be updated.

tykus left a reply on Laravel Make Auth In Api • 1 day ago

Not necessary to add the api_token to the database table with https://github.com/tymondesigns/jwt-auth/wiki/Installation

tykus left a reply on Laravel Make Auth In Api • 1 day ago

I don't want to use Passport or something else

How do you intend to maintain a "session" in that case? Typically a token-based authentication would be used for an API. JWT-Auth is an alternative to Passort

tykus left a reply on Is There A Better Way: Resource Naming • 1 day ago

Route::resource('afbeeldingen', 'Imagecontroller', ['names' => 'images']);

tykus left a reply on Is There Any Date Validation That Accept DOB Only Greater Then 13 • 1 day ago

Date Validation rule accepts a valid strtotime string

'date_of_birth' =>'required|date|before:13 years ago'

tykus left a reply on How To Check User Is 13years Old Or Not Using Carbon • 1 day ago

If you have the person's date of birth:

Carbon::parse($date_of_birth)->age >= 13 

I feel this reads more like what your are trying to achieve; change the comparison to == if the person must be 13, and not 14 or older

tykus left a reply on Restful Child Resources • 1 day ago

Trouble is the index method hates receiving a param.

In that case, it doesn't seem like you have properly set up nested resources. If a URI groups/1/members maps to a controller, then the id for the group should be expected to be received by the index method:

// GroupMemberController

public function index(Group $group)
{
    return $group->members;
}

19th April, 2018

tykus left a reply on Laravel Query Tooo Slow • 2 days ago

Well, you can't expect specific answers to general questions; all we can offer is guidance...

tykus left a reply on Laravel Security Issue • 2 days ago

Are you on a shared hosting? Could your environment variables have been exposed to another site on the same host? There is a thread here which appears to suggest (I have only speed-read the thread) it is possible for environment variables to leak across different sites especially when there might be a long running request. There is a Laravel/Dotenv discussion which suggests that it is paramount to cache your config to avoid this behaviour.

Does any of this seem reasonable?

tykus left a reply on Laravel Security Issue • 2 days ago

Are you exposing the local Whoops page on any error/exception?

tykus left a reply on CSRF Token • 2 days ago

They both are mechanisms for passing the csrf_token into your app's javascript. For some, the window.Laravel.csrfToken was ugly and unnecessary.

tykus left a reply on Change Make:auth Scaffolding To Accept First And Last Name • 2 days ago

You will also need to modify the create method in your RegisterController.

tykus left a reply on How To Limit Audio File To 20 Secound Max File Length?? • 2 days ago

You would need to use a library such as FFMPEG to interrogate the file after it was uploaded.

tykus left a reply on Laravel Checkbox Field Is Always Checked On Edit Form • 2 days ago

I haven't used the Form Builder for years, but I don't know that you can rely on the form-model binding in this case. I expect you should explicitly set the value on each iteration, e.g.:

{{ Form::checkbox('permission[]',$pv->id, $role->hasPermission($pv), array('class'=>'')) }}

and hasPermission() would be a method on the Role model which returns a boolean depending on whether the given permission is attached to that role:

public function hasPermission($permission)
{
    return $this->permissions->contains($permission);
}

tykus left a reply on Laravel Query Tooo Slow • 2 days ago

What is the query that actually runs from all of that setup?

Do you have an appropriate index on columns that your filters are being applied to?

tykus left a reply on Laravel Security Issue • 2 days ago

Because .env file is publicly accessible. This is not a Laravel security issue, it is an issue with how you have deployed your website.

tykus left a reply on Trying To Get Property Of Non-object-Collections • 2 days ago

I updated my last reply to explain the reason for the additional nested and a suggestion to fix this issue.

tykus left a reply on Trying To Get Property Of Non-object-Collections • 2 days ago

Before or after I edited to include [0]?

tykus left a reply on Trying To Get Property Of Non-object-Collections • 2 days ago

Each item in $tests is also an array, not an object:

@foreach($tests as $test)
    {{$test['name']}}
@endforeach

tykus left a reply on Laravel Checkbox Field Is Always Checked On Edit Form • 2 days ago

The third argument to Form::checkbox() determines whether or not it is checked - you have an array in that position which will be truthy.

tykus left a reply on Return Response (json) And Abort • 2 days ago

That would depend on what is going on inside the validateData method - because you do not seem to have a happy path out of the method. If I show you my suggested solution, you will always be throwing an Exception?

tykus left a reply on Update Pivot Table Using Eloquent Is Not Working Correctly. • 2 days ago

What are you doing now?

tykus left a reply on Return Response (json) And Abort • 2 days ago

It simply wouldn't work... you would be returning before dieing

tykus left a reply on Update Pivot Table Using Eloquent Is Not Working Correctly. • 2 days ago

Ok, that is not what updateingExistingPivot is for.

You need to sync, which will detach existing relations, and put the new value(s) in place

tykus left a reply on Update Pivot Table Using Eloquent Is Not Working Correctly. • 2 days ago

Yes, this is because there is nothing to update! Look at the SQL produced, it does not setanything. This is why I asked, what are you updating?

update role_user 
set -- set what??? 
where user_id = 5
and role_id = 1

tykus left a reply on Return Response (json) And Abort • 2 days ago

`validatedData is returning control to the where it was called; this is normal.

Instead, try to throw an exception in validatedData appending the relevant array/json, and handle it in app/Exceptions/Handler.php.

tykus left a reply on Update Pivot Table Using Eloquent Is Not Working Correctly. • 2 days ago

What is not working? It is not clear what you are updating on the pivot table?

tykus left a reply on Update Pivot Table Using Eloquent Is Not Working Correctly. • 2 days ago

Are you using the same $id to find the user as you are to update the pivot. The first argument to updateExistingPivot should be the role_id. But what are the additional attributes that you actually are updating??

User::find($id)->roles()->updateExistingPivot($request->role_id, []);

tykus left a reply on Vuex Data Sent Not Getting Inserted Into The Database On Update • 2 days ago

Have you confirmed that you are actually getting to that route, and therefore the Controller method? Can you dd($request->all()) inside the update method for a sanity check?

tykus left a reply on Vuex Data Sent Not Getting Inserted Into The Database On Update • 2 days ago

I suppose is, does the data get updated in the database - that was your original question?

Is /admin/categories/update/{id} a valid PUT route in your web routes file? Maybe you are getting a 200 response as a false positive.

tykus left a reply on Vuex Data Sent Not Getting Inserted Into The Database On Update • 2 days ago

The name gets sent

If you are getting the form data into the controller method, then Vue/Axios is not the issue. Is the name property fillable on the Category model? Also, update returns a boolean, not a Category instance

18th April, 2018

tykus left a reply on Show Data Per Day With Multiple Tables? • 3 days ago

What does the Collection look like after the merge and grouping?

tykus left a reply on How To Group Multiple Tables Under The Same Date? • 3 days ago

I just gave you a possible solution on the other thread - give it a try

tykus left a reply on How To Group Multiple Tables Under The Same Date? • 3 days ago

Isn't this the same problem as the other thread?

tykus left a reply on Show Data Per Day With Multiple Tables? • 3 days ago

@Ibe if you merge the three collections before grouping, then you would have one collection to pass to the view:

public function show($id)
{
    $child = Child::find($id);

    // Define a Closure that will apply grouping to each Collection.
    $groupingFunction = ;

    $allActs = $child->actone->toBase()
    ->merge($child->acttwo->toBase())
    ->merge($child->$actthree->toBase())
    ->groupBy(function ($act) {
            return $act->created_at->toDateString();
    });

    return view('admin.children.show'(compact('child', 'allActs'));
}

Then inside the view, you would need to check the Model before deciding what to output - one possibility would be to have a partial view created for each resources/views/acts/partials/ActOne.blade.php, resources/views/acts/partials/ActTwo.blade.php and resources/views/acts/partials/ActThree.blade.php, and include the partial dynamically depending on the current model in the loop:

@foreach ($allActs as $date => $acts)
    {{ $date }}
    @foreach($acts as $act)
    @php
        $viewName = (new ReflectionClass($act))->getShortName();
    @endphp

    @include("acts.partials.{$viewName}")
    @endforeach
@endforeach

tykus left a reply on How Many Queries Should $model->save() Run? • 3 days ago

Don't know how you think we might possibly know the answer to that!?!

We're just pointing you to possible reasons why additional queries might result. This is your project, your code, which we do not have sight of.

tykus left a reply on How Many Queries Should $model->save() Run? • 3 days ago

If you don't need the Channel every time you get a Thread, then it is not particularly efficient to be making that query every time.

tykus left a reply on How Many Queries Should $model->save() Run? • 3 days ago

Whenever you are getting a Thread, do you automatically get it's channel also? You might have a $with property on the Thread?

tykus left a reply on How Many Queries Should $model->save() Run? • 3 days ago

Ok, that lifecycle event won't be relevant in this case.

If you don't save the model (comment out that line temporarily), do the queries still happen? Probably, not... in that case, do you touch the parent timestamps; and/or maybe update a last_reply_by?

tykus left a reply on How Many Queries Should $model->save() Run? • 3 days ago

Sorry, missed that :)

Do you have any Model events registered for the Reply?

tykus left a reply on How Many Queries Should $model->save() Run? • 3 days ago

The code on line 76 of RepliesController.php will tell why these queries are being run.

tykus left a reply on How Many Queries Should $model->save() Run? • 3 days ago

Well there might be queries to establish the authenticated user, and his/her authorization to take the action.

Edit Your Profile
Update

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