neeonline

neeonline

Member Since 2 Years Ago

Experience Points 29,120
Experience Level 6

880 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 276
Lessons
Completed
Best Reply Awards 1
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.

18 Apr
4 days ago

neeonline left a reply on Model::paginate() And Then ->append('attribute')

Thank you @ashraam, but to achieve the desired action (append attributes to the data result set and not the result itself), I had to use API Resources.

That way I can use the methods $when, $whenLoaded, etc.

https://laravel.com/docs/5.8/eloquent-resources#introduction

TL;DR: use API (Eloquent) Resources. As everything in Laravel, works like a charm.

neeonline started a new conversation Model::paginate() And Then ->append('attribute')

Hello all,

I'm using Laravel's Database Pagination (https://laravel.com/docs/5.8/pagination#basic-usage), everything work fine...

I came to a dead-[I can't find it in Google]-end. So, let's get a User model with pagination:

$users = User::paginate(15);

If needed I can add query params to the links object:

$users = User::paginate(15)->appends(['queryParam' => 'paramValue']);

But I can't append an attribute to the result set, everything that I tried failed =(

$users = User::paginate(15)->append('userAttribute');

I know it's possible to add the attribute to the protected $appends array, but this append is based on security level. So not all users should see this value.

Any help is appreciate.

Thanks!

16 Apr
6 days ago

neeonline left a reply on Date Serialization

@BOBBYBOUWMANN - Yes, everything last version.

If I force the cast direct in the model, everything works, is just the "global" method that is not working for some reason.

Thank you for your help.

neeonline left a reply on View [admin.users.index] Not Found. In Local It Works For Me, But In The Server Of Heroku Not

Make sure the template exists in production. views/admin/users/index.blade.php

Also run php artisan route:list to double check. Also re-create the cached files in production php artisan cache:clear and re-run the caches.

Best,

neeonline left a reply on Tax Information On Subscription Plans

This is based on where you are. I'm from Florida, that means no tax.

15 Apr
1 week ago

neeonline left a reply on How To Allow Only Admins To Access Specific Pages?

In your route:

Route::middleware('can:admin')->group(function () {
    // Administrator routes here
});

If does not work, add in your AuthServiceProvider::boot:

Gate::define('admin', function ($user) {
    return $user->isAdmin();
});

neeonline left a reply on Watch Array For Changes And Prevent Items To Be Empty

If this is Vue, the val will be an array, just map through and make sure the value is not null.

neeonline left a reply on Pluck Only Name From A Nested Array

I have something similar in my project, this is what I do:

$productNames = collect(array_get($trans, 'data.metadata.product_name'))->pluck('name')->unique()->toArray();

PS: The unique() is just to make sure you don't have the same name more than once.

In the template:

@foreach ($productNames as $name) 
    {{ $name }}    
@endforeach  

I hope this help.

neeonline left a reply on Date Serialization

@BOBBYBOUWMANN - I'm using the correct Carbon class and calling model()->toJson(). No luck...

I don't know if this matter, I'm using SQLite and this serialization should apply to created_at, updated_at, etc. ($table->timestamps and $table->softDeletes).

Thank you.

neeonline left a reply on Watch Array For Changes And Prevent Items To Be Empty

What language is that? JavaScript?

neeonline left a reply on Laravel View()->share Error

@ZFDEVELOPER - Before you declare the share, check if the table exists...

neeonline left a reply on How To Allow Only Admins To Access Specific Pages?

There is a package that In my opinion is super complete:

https://github.com/spatie/laravel-permission

Best,

neeonline started a new conversation Date Serialization

Hello,

I want to have all dates returned from my requests to have a specific format. I followed the documentation at https://laravel.com/docs/5.8/eloquent-serialization#date-serialization

So, in my AppServiceProvider inside the method boot() I have:

Carbon::serializeUsing(function ($carbon) {
    return $carbon->format('Y-m-d\TH:i:s.uP T');
});

But all the dates are still returning in the format Y-m-d i:s:u

What am I doing wrong?

Thank you.

13 Apr
1 week ago

neeonline left a reply on Composer @php Not Found...

@VANDAN - Thank you Vandan, but is not that my composer is not working or the php. Everything is on the $PATH and working fine.

The issue is the pre/post scripts that composer runs that inclues @php (at symbol + php).

neeonline left a reply on Redirect To Custom Page After Registration

After seeing you answer (I forgot that the request is always available through Request::get), why not storing this information into the user table?

That way, next time the user login you can redirect to the right path, regardless the request.

Best regards,

neeonline left a reply on Redirect To Custom Page After Registration

If you check the documentation (https://laravel.com/docs/5.8/authentication), the function redirectTo does not accept any parameter, which means, whoever calls it will not pass any parameter.

How about storing this value in the session, retrieving it in the redirectTo function and removing it?

12 Apr
1 week ago

neeonline started a new conversation Composer @php Not Found...

Ok, this week has being officially a nightmare...

Every time I use composer with Laravel (laravel new project or composer dump-autoload), the pre/post scripts that starting with @php artisan... fails. The error returned is that @php is not recognized.

Let's say @php artisan package:discover fails, If I type and run manually php artisan package:discover everything works...

I've tried to Google it, but Google keeps trolling me since @php is not regognized even between double quotes.

I recently started to use iTerm with zsh (Mac). If someone can help, I appreciate. I'm sure is something stupid that I'm missing.

Thank you.

neeonline left a reply on 8, 9, To 12 Queries Per Index Page, Is It Acceptable?

Sorry for not be able to help you, but what is that dev tool that you are using?

Thank you!

neeonline left a reply on Applying Authorization Policies On Model Query...

@SHEZ1983 - Thanks for your reply. My question is more like a general/best practices question...

Right now I'm using a helper function to apply the same can('view', model) rules and load only what the user should be able to.

My question is more about if this is possible, so all this security logic can be declared in just one place (instead of the gate's authorization and helper function).

Here is an example of the helper function:

function loadProjects()
{
    $user = Auth::user();

    if ($user->isSuperAdmin)
    {
        return Project::all();
    }

    // User is not super admin, that means he can only see projects that belongs to his company
    $query = Project::where('company_id', $user->company_id);

    // There is different access levels inside the company
    if (!$user->isAdmin)
    {
        if ($user->isRegionalManager) {
            // User is a regional manager and can see projects from all offices in the region
            $query->whereIn('region_id', $user->regions->pluck('id')->toArray());
        }
        else if ($user->officeManager) {
            // User is office manager and can see all projects in the office
            $query->whereIn('office_id', $user->officies->pluck('id')->toArray());
        }
        else {
            if ($user->areaManager) {
                // User is area manager and can see all projects in his area
                $query->whereIn('area_id', $user->area_id);
            } else {
                // Low level user, only has access if belongs to project
                $query = $user->projects();
            }
        }
    }

    return $query->get();
}

PS: This is just an example that I coded here, it's not 100% validated.

Thank you.

neeonline left a reply on Applying Authorization Policies On Model Query...

@BOBBYBOUWMANN - Hello @bobbybouwmann , thank you for your answers.

This is clearly one way of doing it. But in that case all projects will be retrieve from the database before the filter method right?

My question is exactly that. How to implement the gate check before querying? If this is possible, not only the database usage will be decrease, the processing time will be a lot faster too.

Thank you for your help.

neeonline started a new conversation Applying Authorization Policies On Model Query...

Hello,

Let's say my App has this models: User, Team, Projects... Using authorization gates I can define if the logged user can view/control a project. No problem there.

public function view(User $user, Project $project)
{
        return $user->teams->contains($project->team);
}

public function control(User $user, Project $project)
{
        return $user->hasPermission('project-edit') && $this->view($user, $project);
}

Now, my question is:

Is it possible to apply the view check while loading the projects for the user?

I know I can use QueryBuilder to create the relations on the query, but if this is possible, I will only have one place to change in the future when the security requirements are changed.

Something like:

$projectsThatUserCanView = $user->teams()
    ->with('projects')
    ->get()
    ->pluck('projects')
    ->toArray();

Thank you!

11 Apr
1 week ago

neeonline left a reply on Impersonate User In SPA Application

Hello all,

Any updates on this matter?

Thank you!

14 Aug
8 months ago

neeonline started a new conversation Passport Re-generate Access Token

Hello all,

I've installed Laravel's Passport with success. Everything works fine. I'm using the following code to generate an Access Token:

$token = $user->createToken('Token Name')->accessToken;

I would like to allow my users to retrieve this Access Token from the UI. My question is:

There is any way to re-generate the Access Token from the user or token model? E.g: $user->tokens->first()->accessToken;

If not, what will be the best solution? Store it on the database?

Thank you.

neeonline left a reply on Pagination "Query\Builder Could Not Be Converted To String"

@Cronix that did the trick. Can you explain why?

Appreciate.

neeonline started a new conversation Pagination "Query\Builder Could Not Be Converted To String"

Hello all,

I have a query with pagination that I need to parse the data before returning it in my API. What is the method to force the paginate to get the results so I can navigate through the data object and not lose the pagination links?

This is an example code:

$result = DB::table('table')
    ->where('column', $filterValue);

if ($start && $end) {
    $start = Carbon::parse($start)->startOfDay()->format('Y-m-d H:i:s.u');
    $end = Carbon::parse($end)->endOfDay()->format('Y-m-d H:i:s.u');

    $result->where('datetime', '>=', $start)
        ->where('datetime', '<=', $end);
}

$result->orderBy('column', 'asc')
    ->paginate(1000);

// Do whatever with the data
//$result->data->each...

return $result;

First I cannot get the $result->data object so I can parse it.

Second, if I just return the $result, I got the error: "Object of class Illuminate\Database\Query\Builder could not be converted to string"

Can someone help me?

Thank you.

19 Mar
1 year ago

neeonline left a reply on Postgresql Copy

Thank you bobbybouwmann.

In the end, I used RAW queries to accomplish this.

If someone has the same question, here is some code snippet:

$file = Carbon::now()->timestamp . '.csv';

Storage::put($file, implode("\n", $records));

DB::raw("COPY table FROM '" . storage_path() . "/app/" . $file . "' DELIMITER ',' CSV");

Storage::delete($file);

Best regards.

16 Mar
1 year ago

neeonline started a new conversation Postgresql Copy

Hello,

I have a large insert that today I'm doing using the following code:

DB::table('FACT_LOCATION')->insert($records);

Where $records is an Array of rows.

Reading the Postgresql documentation I found that I can use the COPY statement to import a file into the database.

How do I do this on Laravel? Export to a CSV file and then import to the database using COPY.

Thank you.

08 Mar
1 year ago

neeonline left a reply on Any Tutorials On How To Implement Roles And Permissions With Laravel Passport?

I remember that this video helped me a lot: https://laracasts.com/lessons/users-and-roles

Using this method, once your API handles the authorization, you will have access to the current user, then just do:

Auth::user()->hasRole('admin') and/or Auth::user()->can('manage_the_forum');

26 Feb
2 years ago

neeonline left a reply on JSON Encode And Chinese Characters.

I found the issue, another script was converting the value using ucwords(mb_strtolower($item->name, 'UTF-8')).

Sorry about that.

neeonline started a new conversation JSON Encode And Chinese Characters.

Good night. I'm having a problem with Eloquent. I have a Postgres DB set in UTF-8. Using DataGrip (or any other DB app) I got the result right.

Eloquent is trying to parse the Chinese characters, so when I do a toJson() or json_encode I got a failure.

I double checked my DB, is working fine, the problem looks like to be with Laravel::DB or Eloquent it-self.

Can anyone help me?

Thank you.

15 Nov
2 years ago

neeonline left a reply on Elixir/Rollout - Bootstrap

I still can't find a solution for this.

Anyone?

10 Nov
2 years ago

neeonline left a reply on Elixir/Rollout - Bootstrap

Hello @ejdelmonico.

This is my code

// boostrap.js (default file included in laravel setup) window._ = require('lodash'); window.$ = window.jQuery = require('jquery'); require('bootstrap-sass');

// app.js require('./bootstrap'); $('#myModal').modal();

// gulpfile.js elixir((mix) => { mix.sass('app.scss') .rollup('app.js'); });

As you can see, it's a basic test. App.js require boostrap.js, witch require lodash, jQuery and Bootstrap. Them I call the modal method from boostrap. But I got the error: app.js:10Uncaught TypeError: $(...).modal is not a function(…)

Thank you.

neeonline started a new conversation Elixir/Rollout - Bootstrap

Hello all, I'm testing rollout.js with Elixir (as seen at https://laravel-news.com/2016/11/introduction-to-rollup-js/).

After calling mix.rollout('app.js') on my gulpfile.js, jQuery works fine on the html page. But I can't use boostrap functions like $('#modal').modal();

Anyone?

Thank you.

16 Sep
2 years ago

neeonline left a reply on Laravel 5.3 Custom PasswordBroker

Never mind.

I was able to use soft delete (https://laravel.com/docs/5.3/eloquent#deleting-models) to achieve my desired functionality.

The only change that I had to do is overwrite the login method on LoginController.php to check if the user company is active (not soft deleted). If user->company = null then I logout the user.

I don't know if this is the best approach, but works fine.

neeonline started a new conversation Laravel 5.3 Custom PasswordBroker

Hello,

I'm having a lot of trouble to understand how to extend/add a new password broker.

My user table has a "active" column, so the resetPasswordLink needs to be sent only if this column is true. To do that I need to extend the password broker to check for that variable.

I read the documentation, but I don't understand how to create/set a new password broker.

https://laravel.com/docs/5.3/passwords#password-customization

Thank you.

10 Sep
2 years ago

neeonline started a new conversation Laravel 5.3 And Wildcard Session.

Hello all,

I have a project that will use wildcard subdomains to configure the UI (companyA.myproject.com, companyB.myproject.com, etc.). This will only be used to load the proper company look and feel.

My problem is, the user can access myproject.com directly and login. After the login it should be redirected to usercompany.myproject.com, but the session is not been shared across the subdomains.

I was reading this question (https://laracasts.com/discuss/channels/servers/different-login-between-domain-and-subdomain), and I want the opposite, lol.

@tankerkiller125 wrote the default in previous versions was wildcard but now looks like they changed it.

Can anyone help/save me?

Appreciate.

neeonline left a reply on Different Login Between Domain And Subdomain

Oh boy. I need to make the wildcard to work. And I can't. If I set the .domain.com (in my case .localhost) I get EncryptCookies exception if I try to log using some subdomain.

How to make the wildcard session work on 5.3?

Thank you!

neeonline left a reply on ACL In Laravel 5.3

This answer helped me a lot! I think this is the only bad thing about Laracasts. I'm new into this framework, so I use the videos as "tutorials" to learn and develop my applications.

Now with the new version of the framework, a lot of lessons are really outdated.

=(