36864

Experience

59,980

85 Best Reply Awards

  • Member Since 1 Year Ago
  • 0 Lessons Completed
  • 0 Favorites

17th August, 2018

36864 left a reply on Error On The Boot Method • 2 days ago

            $model->addActivity($event); // this is the undefined variable
        });```

You forgot to pass in the $event variable. Change that to this:

static::$event(function($model) use($event) {

                $model->addActivity($event); // this is the undefined variable

            });

10th August, 2018

36864 left a reply on Query Model Based On Variable Input That Can Be Null? • 1 week ago

Sorry, I made an error in my example. This should work though:

 Product::when($color !== 'any', function($query) use($color) {
        return $query->where('color', $color);
    })
    ->(...)
    ->get();

9th August, 2018

36864 left a reply on Query Model Based On Variable Input That Can Be Null? • 1 week ago

You could use a conditional clause to decide whether or not you want to apply a filter: https://laravel.com/docs/5.6/queries#conditional-clauses

So, something like

    Product::when($color !== 'any', function($query, $color) {
        return $query->where('color', $color);
    })
    ->(...)
    ->get()

36864 left a reply on PHP Artisan Migrate Leaves Blank Rule • 1 week ago

It's unlikely that swapping mysql for mariadb will solve anything.

Have you tried a fresh laravel install? As in create a new laravel project, run php artisan make:auth, followed by php artisan migrate. If that works, it's likely a problem in your app somewhere. If it doesn't, then look at your infrastructure.

36864 left a reply on PHP Artisan Migrate Leaves Blank Rule • 1 week ago

It might be worth a shot. Reinstalling laravel shouldn't take you very long at all, and it's not like you'd be losing your work.

Ping back if it doesn't solve anything.

36864 left a reply on PHP Artisan Migrate Leaves Blank Rule • 1 week ago

hmm no output at all is a bit weird, especially with verbosity set to max.

Were there any issues at all when you ran composer install?

For general debugging purposes, could you try running php artisan clear-compiled and composer dumpautoload and trying again?

36864 left a reply on Event Subscribers • 1 week ago

Yes, you would still need to create separate events. A subscriber is a replacement for multiple listeners, not for events.

As for queuing, I'm not sure. I think you can, but there's no mention of it in the documentation and I haven't looked into the source for that in a while. If you can, try queuing them and report back with your results.

36864 left a reply on PHP Artisan Migrate Leaves Blank Rule • 1 week ago

What's a blank rule? Do you mean an empty line in your console or something else?

Try running php artisan migrate -vvv to run it at maximum verbosity.

Also, check your logs in storage\logs, there might be a clue there.

8th August, 2018

36864 left a reply on How To Print Province Name Using Province_id In Laravel 5.6 • 1 week ago

Obviously you need to set the variable before you can dump it out...

36864 left a reply on How To Print Province Name Using Province_id In Laravel 5.6 • 1 week ago

...what

dd should be dumping the contents of $town and then immediately terminating execution.

Clear your view cache and try again.

36864 left a reply on How To Print Province Name Using Province_id In Laravel 5.6 • 1 week ago

Or just dd($town_list) in your controller so you can check them all at once

36864 left a reply on Laravel-mix With Toastr Notification (laravel 5.6) • 1 week ago

Are you including your app.js file before that script block in your page?

36864 left a reply on How Many Way Exist To Add Custom Classes To Laravel 5.* ? • 1 week ago

Still unclear on what you're asking.

What does "add custom classes to laravel" mean to you?

You can use any class you define in your project. Laravel is still just php, so even if you don't do the whole autoload thing you can still just import php files and use whatever classes are defined there.

It would be easier to help if we knew exactly what you're looking for.

36864 left a reply on Hash::check Not Matching Password • 1 week ago

That seems to indicate there's no issue with the way the value is stored/retrieved from the database.

That leaves two likely scenarios: You made a typo when first setting the password, or you changed your app's encryption key at some point.

36864 left a reply on Option Value Selecting Using Search Without • 1 week ago

You should encapsulate your code with triple backticks ```

Like this: ``` { code } ```

36864 left a reply on Hash::check Not Matching Password • 1 week ago

There may be some issue with your database's encoding that's messing with the stored string. You're sure you didn't change your app's encryption key between creating this model and trying to check it, right?

Try this (tinker would make it easier to test):

$master = Master::first(); //or fetch any user, doesn't matter
$master->password = Hash::make('selena123');
$master->save();
$master->refresh();
Hash::check('selena123', $master->password);

If that returns false, there's a problem in the way your app is storing/retrieving the hash string. Try copy/pasting the string as it is in your database and pass it directly to the Hash::check method.

36864 left a reply on Hash::check Not Matching Password • 1 week ago

That's expected. Every time you generate a hash, a random salt is generated for it. Did you change your app's encryption key at any point?

Does Hash::check('selena123', Hash::make('selena123')) return true?

7th August, 2018

36864 left a reply on Private Method Injection In A Trait • 1 week ago

Your getRouteKey() calls encodeId() with no parameters, but encodeId requires a parameter to be passed into it.

The example in Optimus' readme file takes advantage of laravel's dependency injection to obtain an Optimus instance in the route action method.

You could have laravel inject optimus into your controller's constructor, and store that optimus instance as a property of the controller. This would then allow you to use that instance in the controller's methods, even if those methods are in a trait.

If you want the trait to be standalone though, you will need to ask the container to resolve an optimus instance for you explicitly.

36864 left a reply on Developing Without A Local VM. • 1 week ago

All you need is an installation of php, your database of choice, and a web server such as apache or nginx. I personally use Bitnami's WAMP stack. Pretty much plug-and-play, no issues at all.

6th August, 2018

36864 left a reply on Private Method Injection In A Trait • 1 week ago

We're gonna need some more information to go on.

Post your trait and model code, along with a code sample where you're encountering the error.

36864 left a reply on How To Modify A Trait In A Composer Package. • 1 week ago

You can declare a new trait that uses the package's trait and overrides the methods you need:

trait MyRouteWithFakeIds {
        use RouteWithFakeIds;

    /**
     * Get the value of the model's route key.
     *
     * @return mixed
     */
    public function getRouteKey()
    {
        return 'foo';
    }
}

Then just use that trait in your models instead of the package's trait.

3rd August, 2018

36864 left a reply on Error: "count(): Parameter Must Be An Array Or An Object That Implements Countable" • 2 weeks ago

https://laravel.com/docs/5.6/queries#aggregates

$active_posts_count = Post::where('isVisible', 1)->count();

36864 left a reply on Production Splash Page • 2 weeks ago

Alternatively, you could put your app in maintenance mode and have the maintenance page be your splash.

36864 left a reply on Laravel 5.6 Register Doesn't Work, No Redirect And No Errors (edited Register Fields) • 2 weeks ago

If you didn't get the data dump, your object probably didn't pass validation.

Dump out the errors variable in your view to make sure you're not missing anything:

@dump($errors)

36864 left a reply on Laravel 5.6 Register Doesn't Work, No Redirect And No Errors (edited Register Fields) • 2 weeks ago

Dump out the data array in the create method to check if you're even hitting it.

protected function create(array $data)
{
    dump($data);
    //rest of your code

36864 left a reply on Laravel 5.6 Register Doesn't Work, No Redirect And No Errors (edited Register Fields) • 2 weeks ago

I'm fairly sure fields are case-sensitive. You're using "Forklift_cert" in your frontend and "forklift_cert" in your backend.

2nd August, 2018

36864 left a reply on Probability Of Same UUID • 2 weeks ago

@abudo at that point you might as well just use the user's id.

31st July, 2018

36864 left a reply on Why Instead Of Appear A Validation Error Appears "Undefined Variable: SelectedRtypes" Error? • 2 weeks ago

Where did you declare $selectedRtype? In the snippets you've showed us, that variable doesn't exist. Did you mean to use $selectedRtypes instead?

36864 left a reply on Online/offline User Status • 2 weeks ago

I suppose you might be able to use websockets to detect when a connection is terminated and push a notification based on that. I wouldn't know how to do that though.

36864 left a reply on Online/offline User Status • 2 weeks ago

Keep a "last_active_at" timestamp and determine online/offline state based on that. Update that value any time the user interacts with the app, and possibly null it out when the user logs out.

To determine if a user is online, simply check if "last_active_at" is not null and greater than current time - 5 minutes.

You could also add a javascript onunload handler to make an ajax request to the logout route, but that's not entirely reliable.

36864 left a reply on Any Way To Compile The Vendors Folder • 2 weeks ago

Those 10 files would have to contain all the information that's in the 10 separate folders.

You'd get no performance benefits, and only a slightly smaller total package size.

I assume you're uploading the vendor folder to your server instead of using composer to fetch your dependencies after uploading your code. This is generally not a good idea unless your development and production environments are exactly the same, as some packages are platform-specific.

Even then, you'd be better off zipping the vendor folder and unzipping it on the server.

36864 left a reply on OOP Question Related To Good Practices - Who Should Have The Property? • 2 weeks ago

@click again, that would limit the ability to have questions in different orders for different quizzes. You'd basically be able to choose between two orders (ascending or descending), instead of being able to define a specific order for every quiz.

For example, if you have questions A through D, you might want Quiz 1 to go B > C >D >A while Quiz 2 goes D > A > B > C, and maybe Quiz 3 goes B > D > C (omitting A).

36864 left a reply on OOP Question Related To Good Practices - Who Should Have The Property? • 2 weeks ago

That would prevent you from reusing questions in different quizzes unless you want every quiz to have the exact same question order.

36864 left a reply on OOP Question Related To Good Practices - Who Should Have The Property? • 2 weeks ago

The Quiz model should have an ordered list of Questions. Questions do not need to know about other Questions.

36864 left a reply on [L 5.6] Where Condition On JSON Columns • 2 weeks ago

Just a side note, this will also work with a regular where statement if you use DB::raw(). This can come in handy if you want to use user input:

Content::where(DB::raw('JSON_LENGTH(`mycolumn`, \'$."programStages"\')), '=', 0)->pluck('id')    
Content::where(DB::raw('JSON_LENGTH(`mycolumn`, \'$."programStages"\')), '>', 0)->pluck('id')

36864 left a reply on Probability Of Same UUID • 2 weeks ago

Like I said, you'll probably get a few billion uuids before there's a meaningful chance of collision.

Even then, the visible part of the user's uuid would be duplicated, but the actual uuid stored in the database would be unique.

36864 left a reply on Probability Of Same UUID • 2 weeks ago

There's a significantly higher chance of collisions for that scenario.

You're still probably looking at a few biliion UUIDs before you'd expect a collision though.

36864 left a reply on Probability Of Same UUID • 2 weeks ago

From wikipedia:

For example, the number of random version 4 UUIDs which need to be generated in order to have a 50% probability of at least one collision is 2.71 quintillion [...]

This number is equivalent to generating 1 billion UUIDs per second for about 85 years, and a file containing this many UUIDs, at 16 bytes per UUID, would be about 45 exabytes, many times larger than the largest databases currently in existence, which are on the order of hundreds of petabytes.

This is, of course, assuming 128 bits of entropy. You'll probably be fine for anything you do. Maybe throw a jackpot error in case a user manages to generate a collision.

36864 left a reply on In ProviderRepository.php Line 208: Class 'Illuminate\Html\HtmlServiceProvider' Not Found • 2 weeks ago

The gist of it is, all web developers know HTML, but not all developers know laravelcollective/html.

If someone who hasn't used that library catches your project in the future, and they need to make a change to a form, they'll have to spend some time learning the library before they can do anything.

Even something as simple as changing a select from single-choice to multiple-choice, which is trivial to do for anyone with even a basic knowledge of HTML, would take a while to figure out if it's done with this library.

And at some point, you might want to switch out that select input for a searchable text box, which may not be a simple task even in HTML, but would be made harder by the fact that not all larvelcollective input tags take the same parameters.

It's really just adding complexity for no gain. A better effect could be achieved by just adding some snippets to your code editor.

30th July, 2018

36864 left a reply on Queue:work Is Stopping The Application • 2 weeks ago

Are you locking the database somehow in your jobs?

36864 left a reply on Unable To Connect To Server's Database • 2 weeks ago

Is your config cached? Try clearing it with php artisan config:clear.

36864 left a reply on Error Encoding Model: Malformed UTF-8 Characters, Possibly Incorrectly Encoded • 2 weeks ago

Could you try a couple more things for me please? Tinker would be great for rapidly testing this:

$employee = Employee::select(...)->find(202);
$employee->toArray();
$employee->jsonSerialize();
$employee->toJson();

36864 left a reply on Error Encoding Model: Malformed UTF-8 Characters, Possibly Incorrectly Encoded • 2 weeks ago

Does calling json_encode() on that emplyee's name directly work?

36864 left a reply on Language Middleware, Based On 'language_id' Integer • 2 weeks ago

You'd need a bit of javascript for that, listening for the select's onchange event to redirect the user. Something like this:

<select onchange="changeLanguage(this.value);">
    {{-- options --}}
</select>

(...)

<script>
    function changeLanguage(val) {
        window.location = val;
    }
</script>

36864 left a reply on In ProviderRepository.php Line 208: Class 'Illuminate\Html\HtmlServiceProvider' Not Found • 2 weeks ago

Easy fix.

composer remove laravelcollective/html

Remove the classes from your providers and aliases.

Write proper html tags. Be thanked by future developers.

36864 left a reply on Relationship Issues ! • 2 weeks ago

whereHas accepts two parameters, the relationship name, and the closure to apply to that relationship.

It does not accept an array as a parameter like with does.

27th July, 2018

36864 left a reply on DigitalOcean Buckets Are Slow • 3 weeks ago

I am checking each image to see if there's a thumbnail version of them on the server. If there isn't, then a thumbnail is generated.

Generating a thumbnail could take a while. Try to pre-generate the thumbnails and see if accessing the images is still slow.

36864 left a reply on Accessor | Can We Set Using Other Eloquent Model • 3 weeks ago

@sanjay23, read @murilo's answer again.

The accessor should not have the same name as the relationship method. Further, it should not try to access itself.

Change the accessor's signature to getStateNameAttribute if you want to get the state's name, and access it with $model->stateName.

36864 left a reply on OK To Mix Web And Api Routes In Same Controller? • 3 weeks ago

Jeff has used web routes for the vast majority of things, rather than ajax.

There's nothing to stop ajax requests from hitting web routes.

The ajax routes are barred of course from using the web auth

Your session and xsrf cookies will be sent with the ajax request, so your app will still go through all the auth mechanisms.

API routes would be used for external access to your application's data. If the user is interacting with your app through the web frontend, and you're not using a completely decoupled client application, even ajax requests should and do use the web session.

Edit Your Profile
Update

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