neeonline

neeonline

Member Since 3 Years Ago

Experience Points 36,700
Experience Level 8

3,300 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 330
Lessons
Completed
Best Reply Awards 4
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

29 Apr
3 months ago

neeonline left a reply on Load Comment With AJAX Without Reloading Page

The return will be a JSON data not a DOM node. To do so you will need to create the node, populate it with the data and then add it to the DOM.

Just search how to do it with jQuery and you will be good to go.

28 Apr
3 months ago

neeonline left a reply on Map By Key And Get Result In Json

Yes you can! Since I don't know the model for Sub, I will suppose it has email and id, status and color...

$subs = Sub::all()->mapWithKeys(function ($item) {
    return [
        $item['email'] => [
            'id' => $item['id'],
            'status' => $item['status'],
            'color' => $item['color']
        ]
    ];
})->toJson();

neeonline left a reply on Vue.js Implement Vue-star-rating With Laravel 5.8 Project

It's really hard to try to help you without the whole code. Somewhere something is missing.

neeonline left a reply on Load Comment With AJAX Without Reloading Page

Regarding Vue.js, go for it. It's magical.

After you finish the Laravel From Scratch series, check this one out: https://laracasts.com/series/learn-vue-2-step-by-step

neeonline left a reply on Load Comment With AJAX Without Reloading Page

In your controller you should have a method like this:

public function store(Request $request)
{
    // I'm not doing any validation here, you should do it
    $newComment = Comment::create([
        'name' => auth()->user()->name.
        'comment' => $request->comment
    ]);

    return $newComment; // Laravel is smart enought to return this as json. Is the same as return response()->json($newComment->toArray());
}

I really recommend you to take time and learn Laravel here at Laracasts. Trust me, worth every penny.

Check this out: https://laracasts.com/series/laravel-from-scratch-2018

neeonline left a reply on What Is The Best Way For Username?

Since mobile devices normally set the first char as uppercase, I always store usernames and emails in lowercase. But then, every time I need to query it, I need to make sure the request parameter is lowercase as well.

neeonline left a reply on Compare Two Datetime With Current Date

Why not use diffInHours?

$now = \Carbon\Carbon::now();
$endDate = \Carbon\Carbon::parse($boostProperty->property_boost_end_date);

$remainingBoostHours = $now->diffInHours($endDate);

Which this idea you can schedule a cronjob every hour and then handle it if remaining is equal 48, 32, 24, 12, 1, etc...

neeonline left a reply on If Condition Blade View

Actually you can use the method forelse with is a foreach and if count at the same time:

@forelse ($kamar as $room)
    <div class="col-sm-3">
        <div class="small-box bg-yellow">
            <div class="inner">
                <h3>{{$room->nomor_kamar}}</h3>
                <p>{{$room->typekamar->nama}}</p>
            </div>
            <div class="icon">
                <i class="fa fa-bed"></i>
            </div>
            <a class="small-box-footer" href="" action="">Bersihkan</a>
        </div>
    </div>
@empty
    <div class="alert alert-warning">
        <h4>Mohon Maaf</h4>
        Untuk sementara, tidak ada kamar yang sedang kotor.
    </div>
@endforelse

neeonline left a reply on If Condition Blade View

"I want show in view, Kamar with status 2, if there are no Kamar with status 2, it will display this :"

Now that make sense...

You need to check how much rooms you have returned. If none then you show the error.

Update your view:

@if($kamar->count())
    @foreach($kamar as $room)
        <div class="col-sm-3">
            <div class="small-box bg-yellow">
                <div class="inner">
                    <h3>{{$room->nomor_kamar}}</h3>
                    <p>{{$room->typekamar->nama}}</p>
                </div>
                <div class="icon">
                    <i class="fa fa-bed"></i>
                </div>
                <a class="small-box-footer" href="" action="">Bersihkan</a>
            </div>
        </div>
    @endforeach
@else
    <div class="alert alert-warning">
        <h4>Mohon Maaf</h4>
        Untuk sementara, tidak ada kamar yang sedang kotor.
    </div>
@endif

neeonline left a reply on Load Comment With AJAX Without Reloading Page

The controller method that stores the comment should return it. On the success method of that Ajax call get it and update the DOM.

This is exactly why Vue is amazing, once you only push the new comment to the comments list and it will render automatically for you.

neeonline left a reply on Eloquent Find() And Count()

If you really want just the count (and not get()->count() to make things faster), you can "cheat".

Model::find($id)->select('id')->get()->count();
Model::where('expression')->select('id')->get()->count();

That way you will only retrieve the ID column from the database and perform the count in the results collection.

It's not the most elegant way to do it, but you cannot have to upgrade to 5.8 (which I recommend, but you will have some work).

You can also always do the query yourself

$count = DB::table($tableName)
                     ->select(DB::raw('count(*) as count'))
                     ->where('column', '=', $value)
                     ->first()
                     ->count;

Best,

neeonline left a reply on Vue.js Implement Vue-star-rating With Laravel 5.8 Project

Since you're not seeing anything at all, do you see in the Network tab in the browser developer tools the compiled JS being loaded?

If is loaded make sure the file is the last compiled one. In other works, check your mix configuration file and your layout.blade.php.

Best,

neeonline left a reply on Eloquent Find() And Count()

Oh I see,

So you want to use the same query method, for example:

Model::where('id', $id)->count() or Model::where('price', '>', 100)->count();

So, the Model::find(id)->count() is the strange one. That should return just one record since the find uses the unique ID column.

Every time I have issues like this (related to Database), I try to see the query logs:

DB::connection()->enableQueryLog();

Model::find(id)->count();

dd(DB::getQueryLog());

I hope that help you.

Best regards,

neeonline left a reply on Using Vue To Authenticate With Laravel/passport?

@MAVERICKCHAN - Thanks for the link, that is the easy part. The issue that I have is more in Vue than in Laravel.

Handle the login, store the token and refresh token, and then if any request fails, try to refresh the token, if refresh fails redirect to login, if works retry the request that failed before.

I'm trying to make the UX the best possible for the user. That way he can't enter the password again and the failed request will be processed with success.

neeonline left a reply on Naming Convention For Models With Relationships

Use the short way. A device is a device. By default it belongs to an user.

In the future if the device belongs to more than one model (let's say a user and a company), you can use morph relations.

neeonline left a reply on Same Page

Please, help others. Add our solution here and choose your own reply as the correct one. This is help anyone with the same issue in the future when they use the search.

Best regards.

neeonline left a reply on Sending String Parameter From Route To View

@XTREMER360 - This transformation that you want needs to happen somewhere.

In your first question you don't want to add it in all controller's methods, so that means it need to be done for all routes that uses it. The only way will be doing it using my second suggestion.

In my opinion this is a cosmetic change and should belong into the view.

neeonline left a reply on Eloquent Find() And Count()

Hold one, you have multiple records with the same ID?

neeonline left a reply on Querying Relationship Existence

What is a sub_job?

Is a relation inside a job?

27 Apr
3 months ago

neeonline left a reply on Using Vue To Authenticate With Laravel/passport?

@MAVERICKCHAN - If is not that much trouble, can you post the link here?

Thanks!

neeonline left a reply on Javascript Class Constructor Fail

Since you can't delete the thread, mark your own answer as the correct one.

Best,

neeonline left a reply on Querying Relations ( 1 To M , M To N)

@STAUDENMEIR - That package is really great!

The permissions example is something that I'm doing manually. I will take a look...

neeonline left a reply on Sending String Parameter From Route To View

Now, if you want to do it BEFORE the controller method is called, you need to transform the route parameter.

Something like this: https://dev.to/samolabams/transforming-laravel-request-data-using-middleware-2k7j

neeonline left a reply on Sending String Parameter From Route To View

You can do that directly in the view:

(I will use @patickadvance code here)

// Controller
public function index($state = 'active')
{
    $users = User::where('state',$state)->get();

    return view('users.index', compact('users', 'state'));
}

// View
{{ \Illuminate\Support\Str::title($state) }} Students

https://laravel.com/docs/5.8/helpers#method-title-case

neeonline left a reply on Error When Tryining To Delete Mysql Database;

This is clearly related to permissions. Check the permissions for the user that you're logging into mysql.

neeonline left a reply on Writing An Api In Laravel

Laravel is amazing, actually is one of the fasted way to create an API.

I recommend this series here @ Laracasts: https://laracasts.com/series/laravel-from-scratch-2018

After you get familiar, check the documentation for API Resources and Passport.

neeonline left a reply on Using Vue To Authenticate With Laravel/passport?

I'm on the same page here... I can't find a tutorial exclusive for Vue + Laravel + Passport...

neeonline left a reply on Naming Convention For Models With Relationships

I agree with @jacey

Later you can use Laravel's collection to return a list of all devices for the user, something like group by, etc.

neeonline left a reply on Multiple Models With Chained One-many Relationships

This is not a complex answer but is a long one. First you need to make sure all relationship are working properly. Second you need to decide how you want to get those IDs in the controller. There is many ways to accomplish this. I will give you the easiest one, but not the smartest or fasted.

// In your route file
Route::get('/user/{user}/page/{page}/image/{image}/comment/{comment}', '[email protected]');
Route::post('/user/{user}/page/{page}/image/{image}/comment', '[email protected]');

// CommentController.php

public function show(Request $request, User $user)
{
    // Check if user has page
    $page = $user->pages()->findOrFail($request->page);

    // Check if page has image
    $image = $page->images()->findOrFail($request->image);

    // Check if image has comment
    $comment = $image->comments()->findOrFail($request->comment);

    return $comment;
}

public function store(Request $request, Use $user)
{
    // Validate the request
    $attributes = $request->validate([
        'body' => 'required',
        'another_field' => 'another_validation_rules'
    ]);

    // Check if user has page
    $page = $user->pages()->findOrFail($request->page);

    // Check if page has image
    $image = $page->images()->findOrFail($request->image);

    // $attributes only contains the validated attributes.
    $newComment = $image->comments()->create($attributes);

    return $newComment;
}

Please forgive any typo since I'm typing directly in the reply form.

neeonline left a reply on If Condition Blade View

Your if statement is right, the query is wrong.

// Will return only Kamar model that contains a typekamar relation AND the status column is 2...
$kamar = Kamar::with('typekamar')->where('status',2)->get();

// Get all Kamars with typekamar relation and ALL status
$kamar = Kamar::with('typekamar')->get();

neeonline left a reply on Vue.js Implement Vue-star-rating With Laravel 5.8 Project

Can you try:

import StarRating from 'vue-star-rating'


Vue.component('star-rating', StarRating);

And if you are using require('./bootstrap'); you don't need window.Vue = require('vue');

Same with the example component, if the file required has only export default you don't need to add .default.

neeonline left a reply on Laravel Return Text/html Instead Of Application/json

Send also the accept header:

"Accept: application/json"

neeonline left a reply on Sum Of Total

You can use the take method:

$cost = $child->events()->take(3)->sum('price');

neeonline left a reply on Automatic Update Database Based On User Input Keys

You can use the Request validation method and then update the model:

public function store(Request $request, Model $model)
{
    $validatedData = $request->validate([
        'username' => 'required_if:email|unique:tableName,username|max:255',
        'email' => 'required_id:username|email|unique:tableName,email',
        'password' => 'sometimes|confirmed'
    ]);

    // Request data is validated, Arr:only (Laravel's Helper) will only return those keys if they exist on the object.
    $model->update( Arr::only($validatedData, ['username', 'email', 'password']) );

    return back()->with('status', 'Model updated!');
}
26 Apr
3 months ago

neeonline left a reply on Hot Reload (Vue) With Valet (SSL)

@SNAPEY - I see your point. But using your general idea, I was able to use vue-cli inside laravel (all frontend is now controlled by vue and not Laravel/Mix).

Thank you!

neeonline left a reply on Hot Reload (Vue) With Valet (SSL)

@SNAPEY - I will give it a shot, in my case the browsersync is related to front-end (Vue) and hot reload.

Your article just prove my point that Laravel mix is a nice touch but is not always the best way to compile assets. If you're using Valet with SSL, etc.

Thanks!

neeonline left a reply on Hot Reload (Vue) With Valet (SSL)

Ok, I give up.

I had to unsecure my valet domain to make it "work". But on the hot reload there is a JS error that is not allowing the reload.

I will search a way to work with Vue CLI inside Laravel.

=(

25 Apr
3 months ago

neeonline left a reply on Hot Reload (Vue) With Valet (SSL)

I tried to remove all browserSync configuration (and follow the documentation), still no success.

=(

neeonline started a new conversation Hot Reload (Vue) With Valet (SSL)

I can't figure out how to make the browser sync/hot reload to work with Valet. I'm using https Valet domains, I tried everything...

This is my mix config:

let siteName = 'mysite';
let valetDomain = '.test';
let userName = 'macuser';

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .tailwind()
    .browserSync({
      proxy: 'https://' + siteName + valetDomain,
      host: siteName + valetDomain,
      open: 'external',
      port: 8000,
      https: {
        key:
          '/Users/' +
          userName +
          '/.config/valet/Certificates/' +
          siteName +
          valetDomain + '.key',
        cert:
          '/Users/' +
          userName +
          '/.config/valet/Certificates/' +
          siteName +
          valetDomain + '.crt'
      }
    });

The changes are not reflected. So I changed the blade template to load the css/js via {{ mix('/js/app.js') }} and then it is trying to load assets from http://localhost:8080 and not https://mysite.test:8000/js/app.js

Any help is appreciated.

18 Apr
3 months 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
4 months 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
4 months 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($tran, '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

Which language is that? JavaScript?

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

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

use Illuminate\Support\Facades\Schema;

if (Schema::hasTable('categories')) {
    view()->share('*', (object) [
        'categories' => Category::all(),
    ]);
}